this is my custom layout xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:adjustViewBounds="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/weather" />
<ImageView
android:id="@+id/like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="@drawable/like" />
<ImageView
android:id="@+id/gps2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="@drawable/gps2" />
<ImageView
android:id="@+id/gps1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="@drawable/gps1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:textSize="14sp"
android:layout_weight="1"
android:textColor="#fff"
android:text="TextView" />
</LinearLayout>
this is my actionbar java code:
ActionBar actionBar = getSupportActionBar();
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mCustomView = layoutInflater.inflate(R.layout.actionbar, null);
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setIcon(null);
this is the activity theme in manifest:
android:theme="@style/Theme.AppCompat.Light"
This is the result :

as you can see , the black layout doesn't fill the width , I don't know why. How can I make custom actionbar to fill the screen width ?
In your actionbar java code, replace
actionBar.setCustomView(mCustomView);
with
actionBar.setCustomView(mCustomView, new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Hope this help you.!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With