-2

I am using android studio. I wanna to use zawgyi font; to change "Android" Text. I can't use this 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 for an 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">

    <!-- The first child in the layout is for the 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>
Peter Phyo
  • 21
  • 1
  • 5

2 Answers2

0

Use the getView() method to invoke Typeface

@Override
public View getView(int position, View convertView, ViewGroup parent) {

            convertView = a.getLayoutInflater().inflate(R.layout.listView, null);

            Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/zawgyi.ttf");
            TextView tv = (TextView) vi.findViewById(R.id.textview); 
            tv.setTypeface(tf);

            return convertView;

        }
zIronManBox
  • 4,967
  • 6
  • 19
  • 35
0
       Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/oneway.ttf");
TextView textview=findViewById(R.id.textviewname);
           textview.setTypeface(typeface);
balu b
  • 282
  • 2
  • 7