這是我的自定義佈局文件:Android的定製爲什麼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>
這是我的動作條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"
這是結果:
正如你所看到的,黑色的佈局沒有填充寬度,我不知道爲什麼。我如何使自定義的操作欄來填充屏幕寬度?
您是否啓用了菜單? – 2015-02-23 05:26:26
android:adjustViewBounds刪除它,它會工作嗎? – 2015-02-23 05:35:04
@Paul我刪除了它,沒有任何更改 – 2015-02-23 06:36:14