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);.
Related
How to make a item "Our Contacts" a white color?(image below)
Current Navigation Drawer
I have a code below, it`s a project template from Android Studio.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
app:headerLayout="#layout/nav_header_main"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimary"
android:fitsSystemWindows="true"
app:itemTextColor="#color/colorAccent"
app:menu="#menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
my activity_main_drawer xml menu file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group>
<item android:title="#string/about_toefl"
android:id="#+id/menu_nav_about_toefl"/>
<item android:title="#string/about_toefl"
android:id="#+id/menu_nav_the_toefl_itp_tests"/>
<item android:title="#string/about_toefl"
android:id="#+id/menu_nav_the_toefl_itp_digital_tests"/>
<item android:title="#string/about_toefl"
android:id="#+id/menu_nav_contact_us"/>
<item android:title="#string/about_toefl"
android:id="#+id/menu_nav_about_us"/>
</group>
<group>
<item android:title="#string/our_contacts">
<menu>
<item android:title="#string/toefl_ucok_org_kz"/>
<item android:title="#string/phone_7_747_857_97_61"/>
</menu>
</item>
</group>
</menu>
this is created with a project template
thank you a lot.
Suppose you have menu item like this -->
<item android:title="Tools"
android:id="#+id/tools">
<menu>
<item="#+i
...........
/>
</menu>
</item>
styles.xml
<style name="changecolor">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">20sp</item>
</style>
MainActivity.java
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
MenuItem tools= menu.findItem(R.id.tools);
SpannableString s = new SpannableString(tools.getTitle());
s.setSpan(new TextAppearanceSpan(this, R.style.changecolor), 0, s.length(), 0);
tools.setTitle(s);
navigationView.setNavigationItemSelectedListener(this);
OR
<com.google.android.material.navigation.NavigationView
android:theme="#style/ThemeOverlay.titleColor"
..>
style:--
<style name="ThemeOverlay.titleColor" parent="">
<item name="android:textColorSecondary">#color/....</item>
</style>
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"
I'm working on putting a Toolbar to screen bottom. After I hide the toolbar title, the title still occupies spaces.
My question is: how can I remove the space?
styles.xml
<resources>
<!-- 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>
</style>
</resources>
In my Activity's onCreate():
toolbar = (Toolbar)findViewById(R.id.bar_bottom);
setSupportActionBar(toolbar);
getSupportActionBar().setSubtitle("");
getSupportActionBar().setDisplayShowTitleEnabled(false);
and in same activity's onCreateOptionsMenu and onOptionsItemSelected:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_bar_bottom, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
and in my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".WelcomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/lbl_test"
android:layout_width="match_parent"
android:layout_height="20sp"
android:text=""
/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/bar_bottom"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
and the 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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".WelcomeActivity">
<item
android:id="#+id/btn_1"
android:orderInCategory="100"
android:title="Button 1"
app:showAsAction="always" />
<item
android:id="#+id/btn_2"
android:orderInCategory="200"
android:title="Button 2"
app:showAsAction="always" />
<item
android:id="#+id/btn_3"
android:orderInCategory="300"
android:title="Button 3"
app:showAsAction="always" />
<item
android:id="#+id/btn_4"
android:orderInCategory="400"
android:title="Button 4"
app:showAsAction="always" />
</menu>
Maybe i'm not too late.
<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/actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/Base.Theme.AppCompat.CompactMenu"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/toolbarMenuLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/ic_action_location" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/ic_action_refresh" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitXY"
android:src="#drawable/ic_action_settings" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
If you use the Toolbar as stated in the classic mode, you cannot align contents as you wish. As you can see in the code above, add a custom layout to your Toolbar, then manage all item click by your own, without setting it as an ActionBar (it sucks, because you have to code all listener and style of course).
By the way, you will notice that the Toolbar will always have a padding in the left: this is normal, also G+ app has it (in the screenshot below, you will see it on the left of Home button).
As far I know once you set the ToolBar as the SupportActionBar it will maintain the space on right for title even if you set it to empty string.
Also when you remove title and have no icon or navigation then you are actually not interested in an ActionBar but just a toolbar. Why not extend the toolbar as below and use so that the items you add to the same by inflating menu would be equally spaced
public class SplitToolbar extends Toolbar {
public SplitToolbar(Context context) {
super(context);
}
public SplitToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public void addView(View child, ViewGroup.LayoutParams params) {
if (child instanceof ActionMenuView) {
params.width = LayoutParams.MATCH_PARENT;
}
super.addView(child, params);
}
}
Instantiate as below and inflate XML
SplitToolbar toolbar = (SplitToolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.inflateMenu(R.menu.menu_toolbar);
Add toolbar like below in Layout XML
<com.xxx.xxx.xxx.SplitToolbar
android:id="#+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary" />
And finally same menu 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=".XXXActivity">
<item
android:id="#+id/action_zoom2fit"
android:icon="#drawable/ic_aspect_ratio_white_24dp"
android:orderInCategory="100"
android:title="#string/zoomfit"
app:showAsAction="always" />
<item
android:id="#+id/action_card"
android:icon="#drawable/ic_action_eject"
android:orderInCategory="100"
android:title="#string/showcard"
app:showAsAction="always" />
<item
android:id="#+id/actionZoom2Track"
android:icon="#drawable/ic_drive_eta_white_24dp"
android:orderInCategory="100"
android:title="#string/zoom2Tracked"
app:showAsAction="always" />
</menu>
NOTE/DISCLAIMER : The extension of Toolbar for this purpose is actually derived from an answer I found sometime ago on StackOverflow itself. I am trying to locate the same to give credit to the person. Will sure add it once I find it.
I believe I got it from this thread
Evenly spaced menu items on Toolbar
I have tried almost all of the things suggested by SO in other questions..still menu item is not showing in action bar.
Before it used to show, but when i used action layout for menu to change the text size, it has stopped showing it.Any help will be appreciated...
This is my menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mnuRecentLookUp" android:title="#string/mnuRecentLookUp" android:icon="#drawable/clock" />
<item android:id="#+id/mnuBookmarks" android:title="#string/mnuBookmarks" android:icon="#drawable/bookmarks" />
<item android:id="#+id/mnuFontSize" android:title="#string/mnuFontSize" android:icon="#drawable/fontsize"/>
<item android:id="#+id/mnuHelp" android:title="#string/mnuHelp" android:icon="#drawable/help" />
<group android:id="#+id/group_term_nav">
<item android:id="#+id/btnTtod"
android:title="#string/ttod"
android:showAsAction="always"
android:actionLayout="#layout/menu_action_layout"
/></group>
</menu>
Below is menu_action_layout.xml
<?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">
<TextView android:id="#+id/actionBarMenuPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="5dp"
android:layout_gravity="center"
android:layout_marginRight="8dp"
android:textStyle="bold"
android:drawablePadding="3dp"
android:gravity="center"
android:scaleType="fitCenter"
/>
</FrameLayout>
Activity code in onCreateOptionsMenu..
public boolean onCreateOptionsMenu(final Menu menu) {
MenuInflater menuInflater = this.getMenuInflater();
menuInflater.inflate(R.menu.nav_home, menu);
// Calling super after populating the menu is necessary here to ensure
// that the
// action bar helpers have a chance to handle this event.
MenuItem pointsMenu = menu.findItem(R.id.btnTtod);
// pointsMenu.setTitle(pointsLeft );
TextView actionBarPoints = (TextView) pointsMenu.getActionView().findViewById(R.id.actionBarMenuPoints);
//actionBarPoints.setText(pointsLeft);
actionBarPoints.setGravity(Gravity.CENTER_VERTICAL);
actionBarPoints.setTextColor(context.getResources().getColor(R.color.white));
actionBarPoints.setTextSize(20);
//actionBarPoints.setTypeface(tfBold);
this.getActionBar().setCustomView(actionBarPoints);
return super.onCreateOptionsMenu(menu);
}
Solved the issue by using below code in styles.xml
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textStyle">bold</item>
<item name="android:textSize">20sp</item>
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>