我试图拥有一个带有自定义视图的简单操作栏,但我得到以下结果:
为了演示,我创建了一个带有黄色背景颜色的简单 xml,它应该占据整个宽度。
这是 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>
我在我的应用程序中使用以下主题:
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"></style>
这是操作栏初始化代码:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
解决方案是添加:
actionBar.setDisplayShowTitleEnabled(false);
代码应该类似于:
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.actionbar);//set the custom view
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)