java - How to get reference to TextView not in setContentView() layout? -


so managed reference textview not in setcontentview() layout i'm still not able set custom font (i'm not getting nullpointerexception anymore, @ least that's good)> code used:

layoutinflater minflater = (layoutinflater) getsystemservice(activity.layout_inflater_service);         view textview= (view) minflater.inflate(r.layout.item, null);          textview mytextview = (textview) textview.findviewbyid(r.id.hellotext);         typeface tf = typeface.createfromasset(getassets(),"fonts/custom_font.ttf");         mytextview.settypeface(tf); 

here's layout i'm getting layoutinflater above:

<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_gravity="center"     android:layout_width="300dp"     android:layout_height="230dp">      <textview         android:id="@+id/hellotext"         android:textsize="20sp"         android:textcolor="#567dc0"         android:background="#fbcb43"         android:gravity="center"         tools:text="@string/hello_world"         android:layout_width="match_parent"         android:layout_height="match_parent" />      <view         android:id="@+id/item_swipe_left_indicator"         android:alpha="0"         android:layout_width="20dp"         android:layout_height="20dp"         android:layout_margin="10dp"         android:background="#a5f" />      <view         android:id="@+id/item_swipe_right_indicator"         android:alpha="0"         android:layout_width="20dp"         android:layout_height="20dp"         android:layout_margin="10dp"         android:layout_gravity="right"         android:background="#5af" />  </framelayout> 

if add android:textstyle="bold" textview in item.xml above works, when try programatically set custom font using code below nothing:

layoutinflater minflater = (layoutinflater) getsystemservice(activity.layout_inflater_service);             view textview= (view) minflater.inflate(r.layout.item, null);              textview mytextview = (textview) textview.findviewbyid(r.id.hellotext);             typeface tf = typeface.createfromasset(getassets(),"fonts/custom_font.ttf");             mytextview.settypeface(tf); 

i not getting errors way.

you programmatically creating new textview inflating xml, , setting custom font on it. reason you're not seeing change text view not on screen. need specify textview added, either setting root in inflate method or programatically adding viewgroup in content layout.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -