安卓4.4奇巧自定义视图动作条不充盈的整个宽度 [英] Android 4.4 Kitkat custom view actionbar not filling the whole width
本文介绍了安卓4.4奇巧自定义视图动作条不充盈的整个宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个简单的动作条带有自定义视图,但我得到以下结果:
有关证明我创建了一个简单的XML黄色背景颜色,这是应该采取全宽度。</ P>
下面是XML:
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT; RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@色/黄
机器人:方向=垂直&GT;
&LT;的TextView
机器人:能见度=水涨船高
机器人:ID =@ + ID / action_save
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ action_save
机器人:重力=中心
机器人:layout_alignParentLeft =真
机器人:layout_centerVertical =真
机器人:TEXTSTYLE =黑体
机器人:layout_marginLeft =10dp
机器人:文字颜色=@机器人:彩色/白
机器人:文本=@字符串/保存/&GT;
&LT; ImageView的
机器人:能见度=水涨船高
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
机器人:背景=@可绘制/ ic_actionbar_logo/&GT;
&LT; / RelativeLayout的&GT;
和我用下面的主题我的应用程序:
&LT;样式名称=AppBaseTheme父=@风格/ Theme.AppCompat.Light&GT;&LT; /风格&GT;
这是动作条初始code:
动作条= getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(假);
actionBar.setDisplayShowCustomEnabled(真正的);
actionBar.setCustomView(R.layout.actionbar);
解决方案
解决的办法是添加:
actionBar.setDisplayShowTitleEnabled(假);
在code应该是这个样子:
动作条= getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(假);
actionBar.setDisplayShowCustomEnabled(真正的);
actionBar.setDisplayShowTitleEnabled(假);
actionBar.setCustomView(R.layout.actionbar); //设置自定义视图
I am trying to have a Simple actionbar with a custom view, but I get the following result:
For demonstration I created a simple xml with a yellow background color which is supposed to take the whole width.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/yellow"
android:orientation="vertical" >
<TextView
android:visibility="gone"
android:id="@+id/action_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/action_save"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textColor="@android:color/white"
android:text="@string/save" />
<ImageView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/ic_actionbar_logo" />
</RelativeLayout>
And I use the following theme for my Application:
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"></style>
This is the actionbar initialization code:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
解决方案
The solution is adding :
actionBar.setDisplayShowTitleEnabled(false);
The code should look something like:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.actionbar);//set the custom view
这篇关于安卓4.4奇巧自定义视图动作条不充盈的整个宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文