菜单项的android系统中更改文字大小 [英] Changing text Size of menu item in android
问题描述
我正在使用操作栏简单的菜单项,在主要活动使用以下code:
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;
}
}
下面是main.xml中菜单的xml:
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>
这是工作,除了它不进行任何更改文字大小。眼下菜单项的文本大小较大,而我想要的字体大小小。所以我在做什么错了?不应该的android:TEXTSIZE
attributute工作?还是有一些其他的方式这样做呢?我认为,文字大小应该从XML设置不从Java,因为它是设计相关的事情。任何建议?
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?
推荐答案
或者你也可以在你使用的主题值/款式项目设置字体大小。在我的情况在AndroidManifest.xml文件中指示的风格是:
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:
android:theme="@style/AppTheme"
所以我对AppTheme风格是现在:
And so my style for the AppTheme is now:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textSize">20sp</item>
</style>
似乎有些奇怪它不会因为尽管该项目工作...
Seems strange it doesn't work for the item though...
这篇关于菜单项的android系统中更改文字大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!