简体   繁体   中英

Android popup with gray background

I have implemented a Popup menu for a image button. Popup background is blue. I want change it to gray. Please help me on this.

My Code :

btn_a.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu a_popup = new PopupMenu(getActivity().getApplicationContext(), a_period);
            a_popup.getMenuInflater().inflate(R.menu.popup_a, a_popup.getMenu());

            a_popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    Toast.makeText(getActivity().getApplicationContext(), "Clicked "+item.getTitle(), Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
            a_popup.show();
        }
    });

You can use Style like this and use "MyTheme" style in your activity or from the whole application.

<style name="MyTheme" parent="android:Theme.Light">
   <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>

<style name="popMenu" parent="@android:style/Widget.PopupMenu">
   <item name="android:popupBackground">@android:color/white</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM