3
我想获得完全像下面的图片。准备自定义操作栏
但我能得到下面的一个现在。这里我有两个问题。
1)如何使这actionbar
工作在所有活动,而不是我现在正在膨胀的单一活动。
2)上述图像好像升高的布局条,但我看起来像一个正常面板。有人可以帮助我如何实现这些?代码片断表示赞赏。
我的电流输出:
我的布局代码膨胀到动作条:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@drawable/ab_customshape" >
<ImageButton
android:id="@+id/homeicon"
android:layout_width="40sp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/ic_launcher"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" >
</ImageButton>
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="My Title"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<ImageButton
android:id="@+id/rightbutton"
android:layout_width="40sp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/ic_launcher"
android:background="@android:color/transparent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
活动代码片断:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initActionBar();
}
private void initActionBar() {
mActionBar = getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
mInflater = LayoutInflater.from(this);
mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("My Own Title");
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
@绘制/ ab_customshape:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="-90"
android:endColor="#DD2ECCFA"
android:startColor="#DD000000"
android:type="linear" />
</shape>
你是什么意思的提升布局栏?请解释一下,只有我可以帮忙。 –
感谢您的回复。但根据您的代码,操作项目和主页图标根据操作栏样式显示,我的意思是只有有空房间。如果我错了,请纠正我。关于第二个问题,你可以看到,在动作条的布局似乎它比动作条下面的画面时看起来升高。在我的帖子的第一张图片中清楚地看到。 – Spike
您可以设置按钮,以显示总是喜欢,.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); –