安卓:无法风格的动作栏 [英] Android: Unable to style action bar
本文介绍了安卓:无法风格的动作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想是这样的
I want to get something like this
为了这个,我已经写了title_layout它看起来像这样
for this I have written title_layout which looks something like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="22sp"
android:background="@drawable/background"/>
</LinearLayout>
和background.xml看起来像这样
and background.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/pink"/>
<stroke android:width="1dip" android:color="@color/pink" />
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
和我已经重写onCreateOptionsMenu方法
and I have overriden onCreateOptionsMenu method as
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getActionBar().setCustomView(R.layout.title_layout);
return true;
}
UI看起来是一样的,即使我不写任何的code。
UI looks the same even if I dont write any of the code.
推荐答案
您应该在您的onCreate()做到这一点
You should do this in your onCreate():
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.title_layout);
这应该工作
这篇关于安卓:无法风格的动作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文