Skip to content Skip to sidebar Skip to footer

(android Studio) Custom Action Bar Layout Isnt Filling Whole Action Bar

before setContentView() LayoutInflater inflater = (LayoutInflater) getSupportActionBar() .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE); View customActionBarView = i

Solution 1:

The answer is Change your style like this

<resources><!-- the theme applied to the application or activity --><stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><!-- Support library compatibility --><itemname="actionBarStyle">@style/MyActionBar</item></style><!-- ActionBar styles --><stylename="MyActionBar"parent="Widget.AppCompat.Toolbar"><!-- Support library compatibility --><itemname="contentInsetStart">0dp</item><!--<item name="background">@android:color/transparent</item>--></style></resources>

And your ActionBar.xml Layout like this: Note: if you changed 'android:layout_height="?attr/actionBarSize"' to 'android:layout_height="match_parent"' it will not fill whole action bar width and if you changed LinearLayout to RelativeLayout with 'android:layout_height="match_parent"' Action bar will fills the entire screen

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:gravity="center"android:background="#0000FF"android:layout_height="?attr/actionBarSize"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:textColor="#FFFFFF"android:text="Aplication"
        /></LinearLayout>

Finally :

setContentView(R.layout.activity_main);

        android.support.v7.app.ActionBaractionBar= getSupportActionBar();
        actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(R.layout.ab);

        ViewcustomActionBarView= actionBar.getCustomView();

Hope this help.

Post a Comment for "(android Studio) Custom Action Bar Layout Isnt Filling Whole Action Bar"