I try to add menu in toolbar.i wrote some code but i have very strange situation.i can't see menu image right side in my toolbar,but when i click it(i mean right side in toolbar)menu is showing
this is a my source
<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.unipay.business.activities.MainActivity">
<item
android:id="#+id/transaction_all"
android:orderInCategory="100"
android:title="#string/history_all"
app:showAsAction="never" />
<item
android:id="#+id/transaction_Income"
android:orderInCategory="100"
android:title="#string/history_income"
app:showAsAction="never" />
<item
android:id="#+id/transaction_Outcome"
android:orderInCategory="100"
android:title="#string/u_history_outcome"
app:showAsAction="never" />
<item
android:id="#+id/transaction_advanced_search"
android:orderInCategory="100"
android:title="#string/u_history_advance"
app:showAsAction="never" />
i ty to create like this menu
this is a my custom Toolbar layout xml code
<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="#dimen/u_common_header_height"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="#style/Toolbar.TitleText">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/u_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/u_sign_open_menu_margin"
android:padding="#dimen/u_sign_open_menu_margin"
android:src="#mipmap/ic_arrow_back_white" />
<ImageView
android:id="#+id/logo_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#mipmap/logo_header"
android:visibility="gone" />
<TextView
android:id="#+id/header_tittle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="72dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="#dimen/u_common_text_size" />
</RelativeLayout>
I initialized my toolbar like this
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
this is a toolbar style
<style name="ToolbarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- android:textColorPrimary is the color of the title text in the Toolbar -->
<item name="android:textColorPrimary">#android:color/holo_blue_light</item>
<!-- actionMenuTextColor is the color of the text of action (menu) items -->
<item name="actionMenuTextColor">#android:color/holo_green_light</item>
<!-- Tints the input fields like checkboxes and text fields -->
<item name="colorAccent">#color/colorPrimary</item>
<!-- Applies to views in their normal state. -->
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="colorControlActivated">#color/colorPrimary</item>
<item name="colorControlHighlight">#color/colorPrimary</item>
</style>
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">21sp</item>
<item name="android:textStyle">italic</item>
</style>
can anyone tell me what i'm doing wrong? as i said menu working in toolbar but i can't see menu image
thanks
try this
import android.support.v7.view.menu.MenuBuilder;
#SuppressLint("RestrictedApi")
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
app:showAsAction="never"
change to
app:showAsAction="always" or "ifRoom"
Related
My toolbar contains :
my own views at start of the toolbar and
then a standard iconized searchview, which can be expanded by clicking the search icon:
When clicking icon to expand the search it overlaps the title:
How can I achieve to expand the searchview only to the end of "MY TITLE"?
Main layout:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/home_appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="#+id/app_toolbar"
android:layout_width="match_parent"
android:layout_height="44dp"
android:theme="#style/myToolbarTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="5dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="#style/myToolbarTheme"
app:title="">
<include layout="#layout/toolbar_title" />
</androidx.appcompat.widget.Toolbar>
<include layout="#layout/toolbar_tabs" />
</com.google.android.material.appbar.AppBarLayout>
<ViewFlipper .....
toolbar_title layout: included in Mainlayout
<ImageView
android:id="#+id/current_view_icon"
android:layout_width="#dimen/toolbar_view_icon"
android:layout_height="#dimen/toolbar_view_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
app:srcCompat="#drawable/ic_chronology" />
<TextView
android:id="#+id/appbar_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="MY TITLE"
android:textColor="#color/navigation_inner_color"
android:textSize="22dp" />
Inflating menu in code:
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
appToolbar = context.findViewById(R.id.app_toolbar);
((AppCompatActivity) context).setSupportActionBar(appToolbar);
appToolbar.inflateMenu(R.menu.main_menu);
R.menu.main_menu with quicksearch:
<?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"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item
android:id="#+id/app_bar_search"
android:icon="#drawable/ic_search_black_24dp"
android:title="Search"
app:actionViewClass="mypackage.toolbar.ArrayAdapterSearchView"
app:showAsAction="always" />
<item
android:id="#+id/app_bar_bookmark"
android:icon="#drawable/ic_bookmark"
android:title="Bookmark"
app:showAsAction="always" />
<item
android:id="#+id/app_bar_menuitem_settings"
android:title="Settings"
app:showAsAction="never" />
</menu>
I think you have 2 options,
Set width to SearchView in styles
<!-- Base application theme. -->
<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="searchViewStyle">#style/MySearchViewStyle</item>
</style>
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
<item name="android:maxWidth">140dp</item>
</style>
Second option is get SeachView instance in onCreateOptionsMenu and calculate width of your toolbar_title layout set remaining width to search bar.
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setMaxWidth(calculatedWidth);
return super.onCreateOptionsMenu(menu);
}
But as per android standards, Search View has to extend completely in toolbar.
For this we have to use searchView.setMaxWidth(Integer.MAX_VALUE);.
I am trying to add a switch to the tool bar. It is showing up, but the color of the switch is not getting picked up from styles.xml. What am I doing wrong?
Home.java
public class Home extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_home,menu);
return true;
}
}
HomeFragment.java
public class HomeFragment extends Fragment {
public HomeFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home, container, false);
}
}
home_activity.xml
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.a.a2.Home">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_home" />
</android.support.design.widget.CoordinatorLayout>
home_content.xml
<fragment 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"
android:id="#+id/fragment"
android:name="com.a.a2.HomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:layout="#layout/fragment_home" />
home_fragment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.a.a2.HomeFragment"
tools:showIn="#layout/activity_home">
</RelativeLayout>
menu_home.xml
<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.a.a2.Home">
<item
android:id="#+id/onOff"
android:title=""
app:actionLayout="#layout/switch_layout"
app:showAsAction="always" />
</menu>
styles.xml
<resources xmlns:android="http://schemas.android.com/tools" xmlns:app="urn:oasis:names:tc:xliff:document:1.2">
<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/actionMenuTextColor</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyToolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">#000000</item>
</style>
<style name="ToolbarTitle" parent="#style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">20sp</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="onOffSwitch" >
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">#D32F2F</item>
<item name="colorControlNormal">#D32F2F</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">#009688</item>
<!-- inactive track color (30% transparency)#42221f1f -->
<item name="android:colorForeground">#303F9F</item>
</style>
</resources>
SwitchLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.SwitchCompat
app:theme="#style/onOffSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch1"
android:checked="true"
android:soundEffectsEnabled="true"
android:scrollbarSize="25dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
1) Why isn' the colors from styles.xml not picked up?
2) The Switch is mentioned in Switch_layout. But it is not mentioned in menu.xml or else, how come it is being shown when I run the app?
2a) Shouldn't there be a reference to switch_layout in some other xml or java code?
I am doing as per this answer
How to change the color of a SwitchCompat
and
How to change the track color of a SwitchCompat
PS:
I would like to change the gradient of the place that I have arrowed.
I have a Toolbar widget on my App with 4 icons and I want to change the space size between these icons to be the same.
Form this:
current design
To be like this:
wanted design
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/action_home"
android:orderInCategory="100"
android:icon="#drawable/white_home"
android:title="#string/action_settings"
app:showAsAction="always" />
<item
android:id="#+id/action_profile"
android:orderInCategory="101"
android:icon="#drawable/white_profile"
android:title="#string/action_settings"
app:showAsAction="always" />
<item
android:id="#+id/action_inbox"
android:orderInCategory="102"
android:icon="#drawable/white_inbox"
android:title="#string/action_settings"
app:showAsAction="always" />
<item
android:id="#+id/action_contacts"
android:orderInCategory="103"
android:icon="#drawable/white_contacts"
android:title="#string/action_settings"
app:showAsAction="always" />
app_bar_main.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_fab_plus"
app:backgroundTint="#color/colorPrimary" />
Thanks in advance.
Here is an example of how you can hack your Toolbar to place items in it filling all its width.
Main point is that you need to declare your own Toolbar's inheritor in which you override addView method:
#Override
public void addView(View child, ViewGroup.LayoutParams params) {
if (child instanceof ActionMenuView) {
params.width = LayoutParams.MATCH_PARENT;
}
super.addView(child, params);
}
UPDATED
If you want to be able to modify space between action items through xml and don't want to extend Toolbar.class and also you use your toolbar as action bar (I meed you calling setSupportActionBar()) then you can change your application theme in styles.xml resource file:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionButtonStyle">#style/MyActionButtonStyle</item>
</style>
<style name="MyActionButtonStyle" parent="AppBaseTheme">
<item name="android:minWidth">20dp</item>
<item name="android:padding">0dp</item>
</style>
I'm using the AppCompat v21 library to create a Lollipop-like interface in my android app. So far it's working great.
Now I want to have to toolbar appear on top of my content in one of my activities.
However, I cannot get it to work. This is what I have so far:
Layout of activity:
<LinearLayout
android:id="#+id/main_parent_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="#style/myAppTheme">
<include layout="#layout/toolbar_setlist_top"/>
<ImageView
android:id="#+id/image"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
Layout of toolbar:
<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"
app:theme="#style/MyActionBar"
app:popupTheme="#style/MyActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:layout_marginTop="0dp" />
Theme:
<resources>
<style name="myAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:activatedBackgroundIndicator">#drawable/list_selector</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/primaryColor2</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="background">#color/primaryColor2</item>
<item name="windowActionBarOverlay">true</item>
</style>
</resources>
Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setlist);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
If you want to place the toolbar on top of your content you can use a FrameLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/main_parent_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_height="100dp"
android:layout_width="40dp"
android:background="#000"/>
</LinearLayout>
<include layout="#layout/toolbar_setlist_top"/>
</FrameLayout>
It doesn't appear that you're acquiring a reference to the toolbar view in your layout anywhere. You need to find the view first, then pass that reference to the setSupportActionBar method:
setContentView(R.layout.activity_setlist);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Assuming that when you say "Now I want to have to toolbar appear on top of my content in one of my activities" you are trying to use the Toolbar as your activity's ActionBar (instead of the old/original ActionBar) you must make your theme's parent theme "Theme.AppCompat.NoActionBar" instead of your current setting *.Light.DarkActionBar. Hope this helps.
I just started using toolbar instead of actionbar in my android app. But it shows a ridiculous settings button at the bottom of the screen and i couldn't find a way to erase it. Please help me with this.
Here is a screenshot for you to understand the problem:
http://i.stack.imgur.com/x1Gwe.png
Here is my code:
SetContentView(Resource.Layout.Main_Activity_Container);
var toolbar = FindViewById<Toolbar>(Resource.Id.Toolbar);
var toolbarBottom = FindViewById<Toolbar>(Resource.Id.BottomToolbar);
SetSupportActionBar(toolbar);
SupportActionBar.Title = "Hello from Toolbar";
SetSupportProgressBarIndeterminate(false);
toolbarBottom.Title = "";
toolbarBottom.InflateMenu (Resource.Menu.tabs);
toolbarBottom.MenuItemClick += delegate(object sender, Toolbar.MenuItemClickEventArgs e)
{
Toast.MakeText(this,
"Bottom toolbar pressed: " + e.Item.TitleFormatted, duration: ToastLength.Short).Show();
indeterminateVisible = !indeterminateVisible;
SetSupportProgressBarIndeterminateVisibility(indeterminateVisible);
};
axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:layout_alignParentTop="true"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary" />
<android.support.v7.widget.Toolbar
android:id="#+id/BottomToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
style="#style/HeaderBar"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/Toolbar"
android:layout_above="#id/BottomToolbar" />
</RelativeLayout>
styles.xml
<style name="MyTheme" parent ="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="windowActionModeOverlay">true</item>
<item name="colorAccent">#FF4081</item>
<item name="android:actionMenuTextColor">#24598a</item>
<item name="android:actionButtonStyle">#style/ActionButtonStyle</item>
</style>
<style name="ActionButtonStyle" parent="#style/Widget.AppCompat.ActionButton">
<item name="android:minWidth">70dip</item>
<item name="android:paddingStart">0dip</item>
<item name="android:paddingEnd">0dip</item>
</style>
tabs.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_share"
android:icon="#drawable/icon"
local:showAsAction="always"
android:title="Edit" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon"
local:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon"
local:showAsAction="always"
android:title="Redo" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon"
local:showAsAction="always"
android:title="Save" />
I also want to change the positions of these menu items. I know that i can use custom components inside of toolbars but i don't get why these menu items always appear in the right hand side.
Thank you.
I had the same issue, I resolved it by following below steps :
First of all to remove the disgusting settings button at bottom do the following :
In your activity, comment getMenuInflater().inflate(...) :
....
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.display_map, menu);
return true;
}
....
This will surely remove settings button from bottom, it did mine.
Now you can create your own menu items as normal views, add as many buttons as you want in your toolbar, whereever you want, see an example :
Toolbar is just a ViewGroup, So, in your toolbar.xml file or whereever you have defined android.support.v7.widget.Toolbar, change as per your requirements of buttons and their positions.
Below shows how to add an button at the center of toolbar, you can change it to your required position :
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/color_toolbar"
android:layout_width="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="button"
android:onClick="buttonHandler"/>
</android.support.v7.widget.Toolbar>