Android edittext更改弹出上下文菜单样式

前端之家收集整理的这篇文章主要介绍了Android edittext更改弹出上下文菜单样式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在长按EditText时更改EditText弹出上下文菜单背景.

我尝试了以下代码,但它不起作用.弹出上下文菜单背景仍未更改.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="dialogTheme">@style/MyDialogTheme</item>
    <item name="popupMenuStyle">@style/MyPopupStyle</item>
</style>

<style name="MyPopupStyle" parent="Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">@color/colorAccent</item>
</style>

<style name="MyDialogTheme" parent="Base.V7.Theme.AppCompat.Dialog">
    <item name="android:colorBackground">@color/colorAccent</item>
</style>

我想要的结果是,弹出上下文菜单背景与品红色的强调色相同.我怎样才能实现它?

解决方法

我的主题
<style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
        <item name="android:popupBackground">@color/popup_background</item>
    </style>

    <style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">#673AB7</item>
        <item name="android:popupMenuStyle">@style/PopupMenu</item>
        <item name="colorPrimaryDark">#512DA8</item>
        <item name="colorAccent">#FF4081</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="android:popupBackground">@color/popup_background</item>
        <item name="android:itemBackground">@color/popup_background</item>
        **<item name="android:actionModeBackground">@color/popup_background</item>**
    </style>

<resources>
    <color name="window_background">#FFF5F5F5</color>
    <color name="popup_background">#FF4081</color>
</resources>

使用弹出上下文菜单

@Override
    public boolean onLongClick(View v)
    {
        PopupMenu menu  = new PopupMenu(this,v);
        MenuInflater inflater = menu.getMenuInflater();
        inflater.inflate(R.menu.drawer_view,menu.getMenu());
        menu.show();
        return false;

    }

如果你能分享弹出的代码,是否可能?

猜你在找的Android相关文章