小编Vij*_*jay的帖子

自定义操作栏不填充父级

自定义操作栏不填充父级.

我正在使用自定义操作栏用于导航抽屉目的.但是我的操作栏会在操作栏的左侧留下一些空间.

我用这样的代码.

// 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);
Run Code Online (Sandbox Code Playgroud)

这是action_custom_action_top_bar文件供参考

此xml文件包含主线性布局,左右图像视图分别用于打开双面抽屉.但是在操作栏的左侧出现了额外的空间可以帮助我吗?

这是我用过的自定义操作栏,我给了操作栏的一些背景颜色和抽屉每侧的两个图像

   <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>
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
2
解决办法
3897
查看次数

标签 统计

android ×1