我正在尝试使用带有自定义 View 的简单操作栏,但得到以下结果:
为了演示,我创建了一个带有黄色背景色的简单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>
这是 Action 栏初始化代码:
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
关于android - Android 4.4 Kitkat自定义 View 操作栏无法填充整个宽度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20172256/