
这个代码是在它下面改变工具栏的一般标题大小,但我需要更改菜单项文本大小.我尝试了很多问题的答案,但它不会直接影响菜单项的大小.我想在项目应用时更改:showAsAction =“ifRoom”.你有什么想法吗?
菜单项(我需要更改此尺寸)
androID:ID="@+ID/try" app:showAsAction="ifRoom" androID:title="0" />样式Xml
<style name="Actionbar.nameText" parent="TextAppearance.AppCompat.Widget.Actionbar.Title"> <item name="androID:textSize">50sp</item> <item name="androID:textStyle">bold</item> </style>工具栏
androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="?attr/colorPrimary" androID:elevation="4dp" androID:theme="@style/themeOverlay.AppCompat.Actionbar"androID:TitleTextAppearance="@style/Actionbar.nameText" app:popuptheme="@style/themeOverlay.AppCompat.light" /> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ID="@+ID/header"> <button androID:ID="@+ID/level_text" androID:background="@drawable/levelstar" androID:layout_wIDth="50dp" androID:layout_height="50dp" androID:text="15" androID:textSize="15sp" androID:layout_centerHorizontal="true"/> /> </relativeLayout>图片
解决方法:
您有两种方法可以执行此 *** 作,具体取决于您希望所有内容的外观/功能.
选项1:
为整个d出菜单创建自定义样式.
唯一的缺点是它会改变所有菜单项而不仅仅是一个.
在Styles.xml中创建样式
<style name="MyMenu"> <item name="androID:textSize">17sp</item> //size desired. <item name="androID:textcolor">@color/colorAccent</item> //Font color <item name="androID:background">#FFFFFF</item> //background</style>然后将此样式应用于工具栏:
<androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="?attr/colorPrimary" app:popuptheme="@style/MyMenu" //important line/>结果变成:
选项编号2
您可以以编程方式将单个菜单项设置为具有自定义字体和样式.要做到这一点,您只需要知道您想要 *** 作的任何菜单项的索引.
在onCreateOptionsMenu中,您需要添加以下内容:
@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); MenuItem item = menu.getItem(0); //here we are getting our menu item. SpannableString s = new SpannableString(item.getTitle()); //get text from our menu item. s.setSpan(new ForegroundcolorSpan(color.RED), 0, s.length(), 0); //here I am just setting a custom color to the menu item. leave this out if you want it left at black. s.setSpan(new relativeSizeSpan(.7f),0,s.length(),0); //here is where we are actually setting the size with a float (proportion). item.setTitle(s); //Then just set the menu item to our SpannableString. return true;}现在这看起来像这样:
总结以上是内存溢出为你收集整理的android – 工具栏菜单项文本大小更改全部内容,希望文章能够帮你解决android – 工具栏菜单项文本大小更改所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)