getSupportActionBar()。setCustomView(view)不会填充整个操作栏 [英] getSupportActionBar().setCustomView(view) does not fill entire actionbar
本文介绍了getSupportActionBar()。setCustomView(view)不会填充整个操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试设置我的应用程序的customview,而我所做的布局并未填充整个操作栏。
我尝试了很多样式设置,但没有一个对我有用。
I'm trying to set the customview of my app and the layout i made does not fill the entire actionbar. I've tried so many style settings but none has worked for me.
这是我的活动代码
View view = getLayoutInflater().inflate(R.layout.actionbar_customized_home, null);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(view);
这是放置为视图的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/actionbar_color"
>
![enter image description here][1]
<ImageView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:src="@drawable/logo"/>
</RelativeLayout>
哪怕是navdrawer之类的菜单项背景,我如何也可以将customview设置为背景色?
Even the background of the menu items like the navdrawer how can I make my customview as background color?
我非常感谢您的帮助
推荐答案
将主容器设置为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:background="@color/actionbar_color"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerInParent="true"
android:scaleType="fitCenter"
android:src="@drawable/logo"/>
</RelativeLayout>
重要的部分是 android:layout_gravity = fill_horizontal
应该可以解决您的问题。
The important part is the android:layout_gravity="fill_horizontal
that should solve your problem.
编辑:
如果不能尝试尝试执行以下操作:
if that did not work try doing this:
View view = getLayoutInflater().inflate(R.layout.actionbar_customized_home, null);
LayoutParams layout = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getSupportActionBar().setCustomView(view, layout);
这篇关于getSupportActionBar()。setCustomView(view)不会填充整个操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文