Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from stephanenicolas/view-factory
Load the custom font in all textviews.
- Loading branch information
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.DS_Store | ||
.idea/* | ||
.idea/ | ||
.gradle | ||
local.properties | ||
/*/out | ||
|
36 changes: 32 additions & 4 deletions
36
app/src/main/java/com/sqisland/android/advanced_textview/CustomFontActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,46 @@ | ||
package com.sqisland.android.advanced_textview; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.graphics.Typeface; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
import android.view.View; | ||
import android.util.AttributeSet; | ||
|
||
public class CustomFontActivity extends Activity { | ||
|
||
private Typeface typeface; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
typeface = Typeface.createFromAsset(getAssets(), "Ruthie.ttf"); | ||
setContentView(R.layout.activity_custom_font); | ||
} | ||
|
||
@Override | ||
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { | ||
//this would apply to all textviews in the app | ||
if (name.equals("TextView")) { | ||
TextView view = new TextView(this, attrs); | ||
view.setTypeface(typeface); | ||
return view; | ||
} | ||
|
||
TextView textView = (TextView) findViewById(R.id.text); | ||
Typeface typeface = Typeface.createFromAsset(getAssets(), "Ruthie.ttf"); | ||
textView.setTypeface(typeface); | ||
return super.onCreateView(parent, name, context, attrs); | ||
} | ||
} | ||
|
||
@Override | ||
public View onCreateView(String name, Context context, AttributeSet attrs) { | ||
//this would apply to all textviews in the app | ||
if (name.equals("TextView")) { | ||
TextView view = new TextView(this, attrs); | ||
view.setTypeface(typeface); | ||
return view; | ||
} | ||
|
||
return super.onCreateView(name, context, attrs); | ||
} | ||
|
||
} |