如何更改Android的一个弹出菜单的文本颜色和大小? [英] How to change the text color and size of a pop up menu in android?

查看:581
本文介绍了如何更改Android的一个弹出菜单的文本颜色和大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在弹出菜单文本颜色没有改变,即使在风格改变。
背景颜色相对于该颜色在styles.xml但文本的颜色和文本尺寸变更不反射的。

Text color in pop up menu is not changing even changed in styles. Background color is changing with respect to the color in styles.xml but the text color and text size are not reflecting.

//Creating the instance of PopupMenu  
                PopupMenu popup = new PopupMenu(mContext, holder.im_overflow);  
                //Inflating the Popup using xml file  
                popup.getMenuInflater().inflate(R.menu.list_overflow_menu, popup.getMenu());  

                //registering popup with OnMenuItemClickListener  
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    // TODO Auto-generated method stub

                    if( item.getTitle().equals("Edit"))
                    {
                        callEdit();
                    }
                    else  if( item.getTitle().equals("Export"))
                    {
                        callShare();
                    }
                    else if( item.getTitle().equals("Delete"))
                    {
                        callDelete();
                    }

                    return true;
                }

                });  

                popup.show();//showing popup menu  

Styles.xml

Styles.xml

    <style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">

</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:popupMenuStyle">@style/PopupMenu</item>


</style>

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
    <item name="android:textColor">#FF01F0</item>
    <item name="android:textSize">12sp</item>


</style>

但它没有改变文字颜色。

But it is not changing the text color.

推荐答案

您可以通过添加此code到styles.xml和清单文件使用它改变文字大小和颜色。对我来说,它的工作。

You can change the text size and color by adding this code to styles.xml and use it in manifest file. For me it worked.

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">           @style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">            @style/myPopupMenuTextAppearanceSmall</item>

<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
<item name="android:textColor">#FF01F0</item>
<item name="android:textSize">12sp</item>
</style>


<style name="myPopupMenuTextAppearanceSmall" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#545656</item>
<item name="android:textSize">15sp</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#545656</item>
<item name="android:textSize">25sp</item>
</style>

这篇关于如何更改Android的一个弹出菜单的文本颜色和大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆