【发布时间】:2015-02-23 05:13:25
【问题描述】:
这是我的自定义布局 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>
这是我的操作栏 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"
这是结果:
如您所见,黑色布局没有填满宽度,我不知道为什么。如何制作自定义操作栏来填充屏幕宽度?
【问题讨论】:
-
您是否启用了菜单?
-
android:adjustViewBounds 去掉这个,能用吗?
-
@Paul 我删除了它,没有任何改变
-
@SpringBreaker 我的活动没有创建菜单,我的意思是我没有 onCreateOptionsMenu 。
-
@mahdiyamani 你是怎么解决的?
标签: android android-layout android-actionbar