I am creating a navigation drawer in android and I have added the items in menu_main.xml but I am not able to change the text size of the menu Specific items. Below is the code menu_main.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/motel"
android:title="Motel">
</item>
<item
android:id="#+id/packages"
android:title="Packages">
</item>
</group>
</menu>
create a style in themes like:
<style name="drawer_text">
<item name="android:textColor">#color/safety_orange</item>
<item name="textAllCaps">true</item>
<item name="android:textSize">22dp</item>
</style>
in activity:
navigationView.setItemTextColor(null);
navigationView.setItemTextAppearance(R.style.drawer_text);
Related
I'm trying to get a menu layout where I have 2 icons next to each other which both have dropdown options. Currently it's being annoying and putting all the items in the default option menu like this:
image
<?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:title="#string/menu_sort"
android:id="#+id/menu_sort"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_sort_24">
<item android:title="Distance"/>
<item android:title="Salary"/>
<item android:title="Date Posted"/>
</item>
<item
android:title="#string/menu_filter"
android:id="#+id/menu_filter"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_filter_list_24">
<item android:title="Freelance"/>
<item android:title="Zero Hour"/>
<item android:title="Part Term"/>
<item android:title="Internship"/>
</item>
</menu>
Maybe this can help....
<?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:title="#string/menu_sort"
android:id="#+id/menu_sort"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_sort_24">
<menu>
<item android:title="Distance"/>
<item android:title="Salary"/>
<item android:title="Date Posted"/>
</menu>
</item>
<item
android:title="#string/menu_filter"
android:id="#+id/menu_filter"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_filter_list_24">
<menu>
<item android:title="Freelance"/>
<item android:title="Zero Hour"/>
<item android:title="Part Term"/>
<item android:title="Internship"/>
</menu>
</item>
</menu>
You add <menu></menu> inside an item and add submenu items there....
How can I decrease the margin of the menu headings as shown in the image. I am using the menu to inflate the items in the drawer. Just want to decrease the top and bottom margin from the menu headings. Here is nav_drawer_items.xml
<item
android:title="MAIN"
android:id="#+id/tabs"
android:checkableBehavior="single">
<menu>
<item
android:id="#+id/nav_home"
android:title="#string/nav_home"
android:icon="#drawable/home_icon"/>
<item
android:id="#+id/nav_movies"
android:title="#string/nav_movies"
android:icon="#drawable/genre_icon"/>
<item
android:id="#+id/nav_originals"
android:title="#string/nav_originals"
android:icon="#drawable/genre_icon"/>
<item
android:id="#+id/nav_live_tv"
android:title="#string/nav_live_tv"
android:icon="#drawable/genre_icon"/>
</menu>
</item>
<item android:id="#+id/others"
android:title="SUPPORT">
<menu>
<item
android:id="#+id/nav_about_us"
android:title="#string/nav_about_us"
android:icon="#drawable/genre_icon"/>
<item
android:id="#+id/nav_feedback"
android:title="#string/nav_feedback"
android:icon="#drawable/genre_icon"/>
<item
android:id="#+id/nav_setting"
android:title="#string/nav_setting"
android:icon="#drawable/genre_icon"/>
</menu>
</item>
You can change the group title padding by adding the following line to your dimens.xml file
<dimen tools:override="true"
name="design_navigation_separator_vertical_padding">0dp</dimen>
I have have a group of items in a navigation drawer menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Group Title">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camera"
android:icon="#drawable/ic_star_black_24dp"
android:title="Import" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_share_black_24dp"
android:title="Gallery" />
</group>
</menu>
</item>
</menu>
I managed to style the menu items following the instruction in this post from stack overflow. Basically modifying these three properties:
This works fine except it only styles the items inside the tag:
So my question is: how can I style (color and background) the titles ("Show Apps" and "Others")?
add following codes in styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">#00F</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#F00</item>
</style>
change first line "name" and "parent" with your app defaults
How to change the text color of submenu in Android? I customize the application theme and override the relative attributes, but it still doesn't work. My menu has two submenus, which are initially hidden, when clicked, it shows. However, the style of submenus can't be modified, while the title of action bar can. This question bothers me all the day, I almost try every ways I find.
This is my code!
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.classsignin.MainActivity" >
<item
android:id="#+id/action_overflow"
android:title="分享"
android:icon="#drawable/drop_select"
android:showAsAction="always"
>
<menu >
<item
android:id="#+id/absent"
android:title="请假"
android:icon="#drawable/absent"
/>
<item
android:id="#+id/refresh"
android:title="刷新课程"
android:icon="#drawable/refresh"
/>
</menu>
</item>
styles.xml
<style name="CustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenu</item>
<item name="android:actionMenuTextColor">#color/blue</item>
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MyActionBarMenu" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MySpinnerItem" parent="#android:style/Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/blue</item>
</style>
Essentially you will want to customise your MenuItem's style by having the android:itemBackground attribute overridden with your custom color/drawable selector in your style.xml and as well a vtextColor` attribute to override.
In case your menu has also submenu's, then you will want as well to style the header title of the submenu, which usually is automatically with White background by overriding the attribute actionBarPopupTheme with your custom style.
style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#drawable/menu_popup_selector</item>
<item name="actionBarPopupTheme">#style/SubmenuHeaderStyle</item>
</style>
<style name="SubmenuHeaderStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#color/colorPrimary</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
</resources>
menu_popup_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color
android:color="#color/colorPrimary"/>
</item>
<item>
<color
android:color="#655611"/>
</item>
</selector>
And you will have something like those screenshots
(1st menu and then the submenu after clicking one item on the 1st menu - the pink header is my submenu header).
Just for you to know when I have the normal menu without submenu would look like this hierarchy views:
<menu>
<item/>
<item/>
<item/>
</menu>
and a menu with submenu as this example of hierarchy views:
<menu>
<item/>
<item/>
<group>
<item>
<menu>
item
item
item
</menu>
</item>
</group>
<item/>
<item/>
</menu>
I'm using ActionBarSherlock, I have ActionBar like in picture:
I would like to change the blue color in e.g. green and I would like to have the selected item of menu with underline (so as in the picture).
My main_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item0"
android:showAsAction="always"
android:title="#string/menu_item0">
</item>
<item
android:id="#+id/item1"
android:showAsAction="always"
android:title="#string/menu_item1">
</item>
<item
android:id="#+id/item2"
android:showAsAction="always"
android:title="#string/menu_item2">
</item>
<item
android:id="#+id/action_overflow"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always">
<menu>
<item android:id="#+id/contact" android:title="#string/submenu_0"/>
<item android:id="#+id/info" android:title="#string/submenu_1"/>
<item android:id="#+id/exit" android:title="#string/submenu_2"/>
</menu>
</item>
</menu>
How can I do it? In which file?
Not sure if you still need help with this but to change the underline on the action bar in action bar sherlock (abs) you just need to replace the background of the action bar with a 9-patch drawable that has a stretachable top seciton and a colour at the bottom (if you search for 'ad_tab_unselected_holo.png' in the abs sample code you can use this and just change the colour in the image).
You then need to att this png and change add the following to your style.xml (note we are changing both android:background & background for backwards compatability).
<style name="CustomTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/ad_tab_unselected_holo</item>
<item name="background">#drawable/ad_tab_unselected_holo</item>
</style>
Then just apply this style in the manifest to your activity as follows;
<activity
android:label="#string/an_activity"
android:name="com.sample.TestActivity"
android:theme="#style/CustomTheme"/>