[英]Custom Action bar layout not getting proper width
I am trying to use a custom layout for action bar with navigation drawer but it seems like the width is not consistent. 我正在尝试为带有导航抽屉的操作栏使用自定义布局,但是宽度似乎不一致。
Here's how it looks like right now: 现在是这样的:
ListView http://imageshack.com/a/img673/867/fTvd6X.png ListView http://imageshack.com/a/img673/867/fTvd6X.png
For some reason the width is not occupied completely on the left of the action bar. 由于某种原因,宽度没有完全占据在操作栏的左侧。
The items currently used in the custom action bar are : app name(Text View), Spinner(Some Text), ImageView on the right of Spinner. 自定义操作栏中当前使用的项目是:应用程序名称(文本视图),微调框(某些文本),微调框右侧的ImageView。
This is how my layout xm looks like: 这是我的布局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>
And sample code for Action bar : 以及动作栏的示例代码:
mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setCustomView(actionBarLayout);
No idea whats going wrong with this. 不知道这怎么了。
Any help will be really appreciated. 任何帮助将不胜感激。 Thanks .. :) 谢谢 .. :)
Is this a space for icon (or logo)? 这是图标(或徽标)的空间吗?
you might try 你可以尝试
getActionBar().setDisplayShowHomeEnabled(false);
but you have flags ActionBar.DISPLAY_SHOW_HOME
and ActionBar.DISPLAY_HOME_AS_UP
, maybe they are important for you... 但是您有标志ActionBar.DISPLAY_SHOW_HOME
和ActionBar.DISPLAY_HOME_AS_UP
,也许它们对您很重要...
also you might try set transparent icon 你也可以尝试设置透明图标
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.