这是我的自定义布局xml文件:
这是结果:
你可以看到,黑色布局没有填满宽度,我不知道为什么。如何使自定义 ActionBar 填充屏幕宽度?
<?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>
这是我的ActionBar Java代码:
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);
这是清单文件中的活动主题:
android:theme="@style/Theme.AppCompat.Light"
这是结果:
你可以看到,黑色布局没有填满宽度,我不知道为什么。如何使自定义 ActionBar 填充屏幕宽度?