android - How to use TypeFace in DrawerItems? -


i using android studio. wanna use zawgyi font; change "android" text. can't use code, typeface typeface = typeface.createfromasset(getassets(), "fonts/zawgyi.ttf");

mainactivity.java

private void adddraweritems() {         string[] osarray = { "android", "ios", "windows", "os x", "linux" };         madapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, osarray);         mdrawerlist.setadapter(madapter);          mdrawerlist.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {           //      toast.maketext(mainactivity.this, "time upgrade!", toast.length_short).show();             }         });     } 

activity_main.xml

<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent">      <!-- first child in layout main activity ui-->     <relativelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:background="#ffffffff"         android:paddingbottom="@dimen/activity_vertical_margin"         android:paddingleft="@dimen/activity_horizontal_margin"         android:paddingright="@dimen/activity_horizontal_margin"         android:paddingtop="@dimen/activity_vertical_margin"         tools:context=".mainactivity">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerhorizontal="true"             android:layout_margintop="100dp"             android:gravity="center"             android:text="holy operating systems, batdroid!"             android:textsize="24sp" />          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentbottom="true"             android:layout_centerhorizontal="true"             android:src="@drawable/batdroid" />      </relativelayout>      <!-- side navigation drawer ui -->     <listview         android:id="@+id/navlist"         android:layout_width="250dp"         android:layout_height="match_parent"         android:layout_gravity="left|start"         android:background="#ffeeeeee" />  </android.support.v4.widget.drawerlayout> 

instead of using android.r.id.text1 textview resource, should create own textview xml layout. this

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:id= "@+id/listview >      <textview         android:id="@+id/listitem"         android:layout_width="match_parent"         android:layout_height="wrap_content" >      </textview </linearlayout> 

the following custom adapter need can set custom styles individual items.

public class listadapter extends baseadapter {  string[] sitenames; activity a;  public listadapter(activity a, string[] sitenames) {     this.a = a;     this.sitenames = sitenames; }  public int getcount() {     return sitenames.length; }  public object getitem(int position) {     return position; }  public long getitemid(int position) {     return position; }  @override public view getview(int position, view convertview, viewgroup parent) {     // todo auto-generated method stub     view vi = convertview;          vi = a.getlayoutinflater().inflate(r.layout.listview, null);          typeface tf = typeface.createfromasset(a.getassets(), "fonts/raleway-thin.otf");         textview tv = (textview) vi.findviewbyid(r.id.listitem);          tv.settypeface(tf);         //whatever other changes want make list items.          return vi;      } } 

then create new adapter "listadapter" class, or whatever name it. can set listview adapter , should go.

you can follow link also


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -