Reputation: 1190
I use this code and i want to add action1 and action2 like picture & color change of this text
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
menu
<?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/ok" android:text="action1" app:showAsAction="never" />
<item android:id="@+id/cancel" android:text="action2" app:showAsAction="ifRoom" />
</menu>
my style
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
</style>
my toolbar
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/theme_color"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Upvotes: 0
Views: 2551
Reputation: 1190
for just menu item text in title case you can add code in your xml file
<bool name="abc_config_actionMenuItemAllCaps">false</bool>
Upvotes: 0
Reputation: 4623
For changing text color, try this, I have not tested but it should work:
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:background="#000"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:itemTextColor="your color"
app:menu="@menu/your menu file" />
Upvotes: 0
Reputation: 16976
If you are using AppCompat_v7
action bar backport, you'll need to use both:
android:showAsAction
and app:showAsAction
as always
.
Check this link: Items not showing in the ActionBar with showAsAction=“always”
And you need to use setTitle
and not name like this:
<?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/ok"
app:showAsAction="always"
android:title="Action1" />
<item
android:id="@+id/cancel"
app:showAsAction="always"
android:title="Action2" />
</menu>
Then, Here is the result:
Upvotes: 1
Reputation: 329
You need to set android:title property rather than android:text for the declared menu items.
<?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/ok" android:title="action1" app:showAsAction="" />
<item android:id="@+id/cancel" android:title="action2" app:showAsAction="ifRoom" />
</menu>
Upvotes: 1
Reputation: 2737
Use below menu file -
<?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/ok" app:showAsAction="always"
android:title="Action1" />
<item android:id="@+id/cancel" app:showAsAction="always"
android:title="Action2" />
</menu>
You need to set android:title="action2"
.
Upvotes: 2