I am using simple menu items in action bar by using following code in main activity:
package com.kaasib.ftpclient;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.ActionBar;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
boolean ret;
if(item.getItemId() == R.id.connection_manager){
ret = true;
}else{
ret = super.onOptionsItemSelected(item);
}
return ret;
}
}
Here is menu xml in main.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/connection_manager"
android:orderInCategory="100"
android:showAsAction="collapseActionView"
android:title="@string/connection_manager"
android:textSize="2sp"
/>
</menu>
It is working except it is not making any change to text size. Right now text size for menu item is bigger while I want font size to be smaller. So what am I doing wrong? Shouldn't android:textSize
attributute work? Or is there some other way to do so? I believe that text size should be set from XML not from java as it is design related thing. Any suggestion?
Add the "android:actionMenuTextAppearance" item for your activities in your styles.xml :
Apply this style to your activity in your Manifest :
Works well, on old API also:
In your style.xml:
In your manifest:
add into style xml file like this bottom code line your custom font size,,
after this
after have to "menu_text_style" add to your NavigationView
Ok, so this is my solution, you can actually use the SpannableString for fetching the text and then changing the font via RelativeSizeSpan (if you want text size relative to the default one) or via AbsoluteSizeSpan (if you want to manually input the text size):
This example increases the size of menu item texts by 50%.
Or you can set the font size in the values/styles item for the theme you are using. In my case the style indicated in the AndroidManifest.xml file is:
And so my style for the AppTheme is now:
Seems strange it doesn't work for the item though...
So it's been a long time since this was asked but I like this solution as steven smiths answer changes every view:
Add this line to NavigationView:
And this to the styles :