How to align the icon on the left side of the application bar in android

I try to click the reverse image of the icon on the left side of the application panel in android, but the icon is displayed in the middle of the application panel (tool). How to align the icon on the right side of the application bar in Android? Please take a look at the image below.

<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="divine.calcify.activities.HomeScreenActivity"> <item android:layoutDirection="ltr" android:id="@+id/hs_back_button" android:icon="@mipmap/ic_back" android:title="@string/homescreen_back" app:showAsAction="always" ></item> <item android:id="@+id/menu_search" android:icon="@mipmap/ic_search" android:title="@string/homescreen_search" android:orderInCategory="1" app:showAsAction="always" app:actionViewClass="android.support.v7.widget.SearchView"/> <item android:id="@+id/menu_notifications" android:icon="@mipmap/ic_divine_notification" android:title="@string/homescreen_notification" android:orderInCategory="2" app:showAsAction="always" /> </menu> 

enter image description here

+6
source share
2 answers

Pragmatically add a return button to a java file (in Activity )

try it

  ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle("Divine"); 
+1
source

You should use Toolbar instead of ActionBar . Toolbar gives you the freedom to freely design it like a normal view.

If you do not have a built-in toolbar, the problem does not occur.

  • Extend class to ActionBarActivity
  • Update theme with parent Theme.AppCompat.Light.NoActionBar

    <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>--> </style>

  • Create your own toolbar layout.

      <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="100dp" android:minHeight="100dp" android:background="@color/colorPrimary"> <!--your views here--> </android.support.v7.widget.Toolbar> 
  • Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);

Full demo here

0
source

All Articles