繁体   English   中英

自定义操作栏布局未获得正确的宽度

[英]Custom Action bar layout not getting proper width

我正在尝试为带有导航抽屉的操作栏使用自定义布局,但是宽度似乎不一致。

现在是这样的:

ListView http://imageshack.com/a/img673/867/fTvd6X.png

由于某种原因,宽度没有完全占据在操作栏的左侧。

自定义操作栏中当前使用的项目是:应用程序名称(文本视图),微调框(某些文本),微调框右侧的ImageView。

这是我的布局xm的样子:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:padding="10dp"
        android:layout_gravity="center_vertical|left"
        android:src="@drawable/someIcon" />

    <TextView
        android:id="@+id/appTextLabel"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:padding="10dp"
        android:text="someAppName"
        android:textColor="#555555"
        android:textSize="24sp"
        android:textStyle="bold" />

    <Spinner
        android:id="@+id/locationSpinner"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#000"
        android:spinnerMode="dropdown" />

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_gravity="center_vertical|right"
        android:src="@drawable/location_down_icon" />
</LinearLayout>

以及动作栏的示例代码:

    mActionBar = getSupportActionBar();

    mActionBar.setDisplayShowTitleEnabled(false);

    mActionBar.setDisplayShowCustomEnabled(true);

    mActionBar.setCustomView(actionBarLayout);

不知道这怎么了。

任何帮助将不胜感激。 谢谢 .. :)

这是图标(或徽标)的空间吗?

你可以尝试

 getActionBar().setDisplayShowHomeEnabled(false);

但是您有标志ActionBar.DISPLAY_SHOW_HOMEActionBar.DISPLAY_HOME_AS_UP ,也许它们对您很重要...

你也可以尝试设置透明图标

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM