我的自定义操作栏视图未填充高度..它显示在图片中。
我正在使用AppCompatActivity(不推荐使用ActionBarActivity)。
ActionBar actionBar = pActivity.getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(pActivity);
View mCustomView = mInflater.inflate(R.layout.action_new, null);
TextView text_back = (TextView) mCustomView.findViewById(R.id.text_back);
text_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pActivity.onBackPressed();
}
});
TextView text_reset = (TextView) mCustomView.findViewById(R.id.text_reset);
text_reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(mCustomView);
Toolbar parent = (Toolbar) mCustomView.getParent();
parent.setContentInsetsAbsolute(0, 0);
以下是action_new布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@color/bottom_green">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="BACK" android:id="@+id/text_back" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:textColor="@color/text_in_green" android:padding="10dp" android:textSize="18dp" android:paddingLeft="15dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RESET" android:id="@+id/text_reset" android:textColor="@color/text_in_green" android:textSize="18dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:padding="10dp" android:paddingRight="15dp" android:paddingEnd="15dp"
/>
</RelativeLayout>
答案 0 :(得分:0)
快速修复,将android:minHeight="?attr/actionBarSize"
添加到RelativeLayout
为了更好地处理和更自由地定制,您应该使用工具栏
答案 1 :(得分:0)
您添加了10 dp的填充。
从两个TextView中删除android:padding="10dp"
。它应该工作正常。