1. Modify the title margin
Modify the margin using the system's app properties to introduce use, i.e.:
xmlns:app="http://schemas.android.com/apk/res-auto"
Like what:
<Android.support.v7.widget.Toolbarxmlns:app= "http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout _width= "match_parent" android:layout_height="wrap_content" android:layout_marginbottom="1DP" android:background="? attr/colorprimary" android:minheight= "? attr/actionbarsize" Android : orientation= "vertical" app:contentinsetleft="10DP"/>
Of course, can also be modified in the style.xml, their own research it;
2. Modify the padding value of navigation icon
Modify the padding value, you need to modify it in Style.xml, and here we modify the pading value of navigation:
Widget.AppCompat.Toolbar.Button.Navigation
Like what:
1. Define Style
<style name= " Mytoolbarnavigationbuttonstyle "parent=" @style/ Widget.AppCompat.Toolbar.Button.Navigation "> <item name= "android:minwidth" >0dp</item> <item name= " android:p adding ">@dimen/margin_horizontal_large</item> <item name=" Android: ScaleType ">centerInside</item> </STYLE>
Apply in 2.app Themes
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="toolbarNavigationButtonStyle">@style/myToolbarNavigationButtonStyle</item> </style>
3.title Center
Toolbar can be customized layout, you can add a TextView in the toolbar to achieve, in lieu of title;
Like what:
1. Layout
<?xml version= "1.0" encoding= "Utf-8"?><Android.support.v7.widget.ToolbarAndroid:id="@+id/toolbar"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="? Actionbarsize"Android:background= "@null" app:popuptheme= "@style/ ThemeOverlay.AppCompat.Light "app:theme=" @style/apptheme " > <textview android:id= "@+id/toolbar_title" style= "@style/ TextAppearance.AppCompat.Widget.ActionBar.Title "android:layout_width=" wrap_content "android:layout_height=" Wrap_ Content "android:layout_gravity=" center "/></ANDROID.SUPPORT.V7.WIDGET.TOOLBAR>
2. Initialization
View v = findViewById(R.id.toolbar);if (v != null) { toolbar = (Toolbar) v; setSupportActionBar(toolbar); toolbarTitle = (TextView) v.findViewById(R.id.toolbar_title); if (toolbarTitle != null) { getSupportActionBar().setDisplayShowTitleEnabled(false); }}
3. Use
Set the title two ways:
(1) directly in SetText ();
(2) Designation of title in Androidmanifest.xml;
(3) If there is baseactivity, the solution is as follows:
Activity has a ontitlechanged interface, which is called in the activity's onpostcreate and settitle;
protected void onPostCreate(@Nullable Bundle savedInstanceState) { if (!isChild()) { mTitleReady = true; onTitleChanged(getTitle(), getTitleColor()); } mCalled = true;}
So just overload the method in Baseactivity, as shown below:
@Overrideprotected void onTitleChanged(CharSequence title, int color) { super.onTitleChanged(title, color); if (toolbarTitle != null) { toolbarTitle.setText(title); }}
Reference-point Me
4. Modify the padding value of the menu
Define the style value:
name="mToolbarStyle" parent="@style/Widget.AppCompat.Toolbar"> <item name="android:paddingRight">0dp</item> <item name="android:paddingLeft">13dp</item> </style>
Use:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="1dp" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:orientation="vertical" style="@style/mToolbarStyle"/>
The above method, on some machines will be invalid, we have the above approach, please tell me, thank you!
5. Reference
Modify some properties of toolbar
Toolbar learning to use
Android-toolbar navigation Style