Florian Mac Langlade
Florian Mac Langlade

Reputation: 1903

Change actionbar text padding

Is there any way to change right padding of text in ActionBar ?

Here my code :

Styles

<style name="ABTheme" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
    <item name="android:textSize">14sp</item>
    <item name="android:paddingRight">20dp</item>
</style>

Menu

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/test"
        android:title="Test"
        app:showAsAction="always|withText" />
</menu>

Upvotes: 0

Views: 540

Answers (1)

Alexander Goncharenko
Alexander Goncharenko

Reputation: 954

Try to use Android Toolbar with AppCompat v21 insdead of ActionBar.

In your main view layout put somewhere the following code:

<android.support.v7.widget.Toolbar
    android:id=”@+id/my_awesome_toolbar”
    android:layout_height=”wrap_content”
    android:layout_width=”match_parent”
    android:paddingRight="@dimens/YOUR_PADDING"
    android:minHeight=”56dp”
    android:background=”@color/colorPrimary” >
    <!-- Put whatever you want here -->
 </android.support.v7.widget.Toolbar>

Then in your Activity or Fragment set Toolbar as ActionBar

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity_layout);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);
}

U can add menu as in ActionBar if U want. Set custom title and add any paddings to it (but dont forget to set no title style) or getSupportActionBar().setDisplayShowTitleEnabled(false);. More information here.

Upvotes: 1

Related Questions