I want to change font type of textview when i click the respective item in menu subitem. I have font options Kadwa, Vollkorn and Default which is droid sans. I have been able to show toast on click. I am a newbie to android studio and below is my code so far and I have attached a screenshot below. No idea what to do next. Thanks for your help. Image
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_text, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.item2) {
Toast.makeText(this, "Night mode", Toast.LENGTH_LONG).show();
return true;
}
if (id == R.id.item3) {
Toast.makeText(this, "Fonts", Toast.LENGTH_LONG).show();
return true;
}
if (id == R.id.font1) {
Toast.makeText(this, "Font 1", Toast.LENGTH_LONG).show();
return true;
}
if (id == R.id.font2) {
Toast.makeText(this, "Font 2", Toast.LENGTH_LONG).show();
return true;
}
if (id == R.id.font3) {
Toast.makeText(this, "Font 3", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
Menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/settings"
app:showAsAction="always">
<menu>
<item android:id="@+id/item2"
android:title="@string/night_mode"
android:icon="@drawable/ic_night"
app:showAsAction="withText" />
<item android:id="@+id/item3"
android:title="@string/font"
app:showAsAction="never" >
<menu>
<item android:id="@+id/font1"
android:title="Kadwa"/>
<item android:id="@+id/font2"
android:title="Vollkorn"/>
<item android:id="@+id/font3"
android:title="Default"/>
</menu>
</item>
</menu>
</item>