我的自定義操作欄視圖不是填充高度..它顯示爲圖片。自定義操作欄視圖 - 不填充高度
我使用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>
你檢查過'action_new'是否有任何'margin/padding'? – hrskrs
請附上「action_new」的XML佈局。否則很難回答你的問題。 –
請讓我看看佈局文件,以便我們清楚地瞭解它。 –