I am trying to apply a theme on my application. Everything is working fine except the menu that I am inflating with a display_menu.xml file. What I am doing wrong here?
My styles.xml
<style name="AppTheme.Dark">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:colorBackground">#color/colorBackground</item>
<item name="android:textColorSecondary">#color/textColorPrimary</item>
<item name="android:windowBackground">#color/colorBackground</item>
<item name="android:textColorSecondaryInverse">#color/textColorPrimary</item>
<item name="android:textColor">#color/textColorPrimary</item>
<item name="cardStyle">#style/CardView.Dark</item>
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
</style>
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
<item name="android:textAppearanceListItem">#style/MyText</item>
</style>
<style name="MyText">
<item name="android:textColor">#color/colorAccent</item>
</style>
My display_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_refresh"
android:title="#string/action_refresh"
app:showAsAction="never" />
</menu>
I'm inflating it like
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.display_menu, menu);
return true;
}
My menu item is displaying like this:
This is the drawable I am trying to put in background:
I am trying to give the background of menu item as my colorPrimary** and text color as textColorPrimary
This Helps me
Add popupMenu style to ur AppTheme:
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
.............
</application>
Related
I want to change the circle color of radio button (now is pink, (see the image below)) to dark blue for all items of menu.
That's my menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.aoutir.mohamed.movies.MainFragment"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--<item-->
<!--android:id="#+id/action_refresh"-->
<!--android:title="#string/Refresh"-->
<!--android:orderInCategory="200"/>-->
<group android:checkableBehavior="single">
<item
android:id="#+id/action_popular"
android:orderInCategory="100"
android:title="#string/action_popular"
app:showAsAction="never" />
<item
android:id="#+id/action_rated"
android:orderInCategory="200"
android:title="#string/action_rated"
app:showAsAction="never" />
<item
android:id="#+id/action_favourites"
android:orderInCategory="300"
android:title="#string/action_favourites"
app:showAsAction="never" />
</group>
</menu>
style.xml (here is my style of whole application):
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<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="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--<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="colorAccent">#color/colorPrimary</item>-->
<!--<item name="android:textColor">#android:color/black</item>-->
<!--</style>-->
<style name="AppTheme.NoActionBar" parent="Base.Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MovieTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Movies.NoTitle</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="ActionBar.Solid.Movies.NoTitle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#mipmap/pop_corn</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar" >
<item name="overlapAnchor">false</item>
<item name="android:overlapAnchor" tools:ignore="NewApi">false</item>
</style>
<style name="AppTheme.PopupOverlay" parent="Base.ThemeOverlay.AppCompat.Light">
</style>
<style name="CircularProgress" parent="Theme.AppCompat.Light">
<item name="colorAccent">#color/sky_blue</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#mipmap/ic_sort</item>
<item name="android:contentDescription">#string/action_sort</item>
</style>
</resources>
and java code that is associated to my menu (check if item is selected and do some action):
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main_fragment_menu,menu);
super.onCreateOptionsMenu(menu,inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_popular:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.action_rated:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.action_favourites:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Thanks in advance for any help.
To style the radio buttons inside your overflow menu's popup window, you can set colorAccent (for the selected radio button) and colorControlNormal (for the other buttons) in your toolbar's popup theme.
First, create a <style> to use as the theme:
<style name="MyPopupTheme">
<item name="colorAccent">#00f</item>
<item name="colorControlNormal">#00f</item>
</style>
Then, set this style as your app:popupTheme in your layout, on whatever Toolbar you're using for your activity's action bar:
<android.support.v7.widget.Toolbar
app:popupTheme="#style/MyPopupTheme"
.../>
Use this <android.support.v7.widget.AppCompatRadioButton for your own color on radio button :
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="#color/Color" />
Or, you can use style for this :
<style name="RadioButtonStyle" parent="AppTheme">
<item name="colorControlNormal">#color/pink</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:textColorSecondary">#color/black</item>
</style>
I want change background of menu and set it to blue. Now background of my menu is black.How to change this?
Menu xml file :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.nabege.AboutUsActivity" >
<item
android:id="#+id/help"
android:title="#string/help" />
<item
android:id="#+id/setting"
android:title="#string/setting"/>
Java codes :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about_us, menu);
return super.onCreateOptionsMenu(menu);
}
Put the following styles in your styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_color</item>
<!--<item name="colorPrimaryDark">#color/primary_color</item>-->
<item name="colorAccent">#color/primary_color</item>
<item name="actionBarStyle">#style/AppThemeActionBarStyle</item>
</style>
<style name="AppThemeActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#color/your_background_color</item>
</style>
Hope this helps.
I am trying to style the items of my popup so they look like a list of buttons below eachother. The only problem is that I can't get to change anything of the popup items. I have tried to set a global popupMenuStyle in my app style but that didn't to anything. I tried to set an actionLayout on the menu items but still no change.
How can I change the styling of my popup menu items?
My menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test1"
android:title="Test" />
<item android:id="#+id/test2"
android:title="Test 2" />
</menu>
How I open the popup menu:
PopupMenu popupMenu = new PopupMenu(getContext(), mButton);
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.show();
Try this as part of your styles.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#FFFFFF</item>
<item name="android:divider">#444444</item>
<item name="android:dividerHeight">1px</item>
<item name="android:background">#FFFFFF</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
<item name="android:background">#FFFFFF</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#000000</item>
<item name="android:textSize">18sp</item>
<item name="android:background">#FFFFFF</item>
</style>
</resources>
and then in your xml layout file for the activity add this line:
style="#style/AppTheme"
or in your AndroidManifest.xml file, add this to the application tag:
android:theme="#style/AppTheme"
This will affect how Android renders a popup menu in your app.
I have set a popup menu in my application.But i want my pop up in material design.How can i do this?
My pop up menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item_movies"
android:showAsAction="ifRoom|withText"
android:title="Movies"
android:visible="true"/>
<item
android:id="#+id/item_music"
android:showAsAction="ifRoom|withText"
android:title="Music"
android:visible="true"/>
<item
android:id="#+id/item_comedy"
android:showAsAction="ifRoom|withText"
android:title="Comedy"
android:visible="true"/>
</menu>
It looks something like this
I want something like this
COde
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this.getApplicationContext(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.song_popup, popup.getMenu());
popup.show();
/*Toast.makeText(this, "pop up test",
Toast.LENGTH_LONG).show();*/
}
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/myPrimaryColor</item>
<item name="colorPrimaryDark">#color/myPrimaryDarkColor</item>
<item name="colorAccent">#color/myAccentColor</item>
<item name="android:textColorPrimary">#color/myTextPrimaryColor</item>
<item name="android:navigationBarColor">#color/myNavigationColor</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:windowBackground">#color/myWindowBackground</item>
<item name="android:windowContentTransitions">true</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="ToolBarStyle" parent="">
<item name="android:elevation">#dimen/toolbar_elevation</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
</resources>
I'm trying to implement this in a gridview .(like in google play music)
try to use android.support.v7.widget.PopupMenu instead of android.widget.PopupMenu
I want to change default divider color of my option menu, so can give me some suggestion or technical?
Its working for me in Navigationmenu.
This below line is mandatory.
<item name="android:listDivider">#color/white</item>
//This is ur style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:listDivider">#color/white</item>
</style>
//This is ur menu item.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_profile"
android:icon="#drawable/m_profile"
android:title="#string/my_profile" />
<group android:id="#+id/my_id">
<item
android:id="#+id/nav_coming"
android:icon="#drawable/m_coming"
android:title="#string/comingsoon" />
</group>
</group>
</menu>
you can do it by setting theme to your popup menu
use below code in your style.xml file in res folder
<style name="MyThemePopup" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
<item name="android:dividerHeight">2px</item>
<item name="android:divider">#F00</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/opaque_black_color_dark</item>
</style>
above code is for creating theme where <item name="android:divider">#F00</item> is use for setting color to divider
after that you can set created theme to your activity in which popup menu is present through manifest file
<activity
android:name="com.android.MainActivity"
android:theme="#style/MyThemePopup" />
hope this code will help you to achieve your requirement happy coding :)
Does nothing for me, maybe because of the appCompat version?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:divider">#color/ucc_blue</item>
</style>
It doesn't matter if i put it in the MyActionBar style or in the AppTheme style both won't work. But setting the divider height does make my OptionMenu scrollable....
Maybe it doesn't work because they are subMenuItems?
add this item to the app theme:
<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
</style>
<style name="MyDropDownListView" parent="#android:style/Widget.ListView.DropDown">
<item name="android:divider">#color/transparent</item>
</style>
For those who have not found the answer yet for this problem, this is how it worked for me and hope it will work for you as well:
<style name="PopupMenu">
<item name="android:itemBackground">#color/background_medium_gray</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/BackgroundGray</item>
<item name="android:dividerHeight">1dp</item>
</style>
Context context = new ContextThemeWrapper(getActivity(), R.style.PopupMenu);
final PopupMenu popupMenu = new PopupMenu(context, view);
final MenuInflater menuInflater = popupMenu.getMenuInflater();