自定义动作栏未填满父元素。
我正在使用自定义动作栏来实现导航抽屉功能。 但是我的动作栏在左侧保留了一些空间。
我使用的代码如下。
// to inflate custom view
LayoutInflater inflator= (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v=inflator.inflate(R.layout.custom_action_top_bar, null);
getActionBar().setHomeButtonEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowCustomEnabled(true);
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
getActionBar().setCustomView(v);
View v1 = getActionBar().getCustomView();
LayoutParams lp = (LayoutParams) v1.getLayoutParams();
lp.width = LayoutParams.FILL_PARENT;
v1.setLayoutParams(lp);
这是用于参考的action_custom_action_top_bar文件
这个xml文件包含一个主线性布局,左右两侧分别有用于打开两侧抽屉的imageview。但是在操作栏的左侧出现了多余的空间,有谁能帮我解决一下?
这是我使用的自定义操作栏,我为操作栏设置了一些背景颜色,并为每个侧面添加了两个图像以用于抽屉。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum="1.0" >
<ImageView
android:id="@+id/IV_leftIcon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="@color/light_green"
android:src="@drawable/header_menu_btn" />
<TextView
android:id="@+id/actionText"
style="@style/action_bar_top_text_size"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".6"
android:background="@color/light_green"
android:drawableRight="@drawable/header_dropdown_arrow"
android:gravity="center"
android:text="Sample"
android:textColor="@color/white" />
<ImageView
android:id="@+id/IV_rightIcon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="@color/light_green"
android:src="@drawable/plus_btn" />
</LinearLayout>