现在我的 Activity 标题在左侧显示为 < Title
然后另一个菜单项显示在右侧。我想将标题居中并省略 <
。我怎么做?我正在使用典型的菜单,我称之为使用
public boolean onOptionsItemSelected(MenuItem item)
和
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.yesterday, menu);
return true;
}
编辑:
我设法使用它来显示
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_yesterday);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.yesterday_title_bar);
哪里yesterday_title_bar
是一个relativeLayout
但它显示的是 View 高度的一半。所以我创建了以下样式。但是当我在 list 中应用样式时。 list 显示找不到资源。
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">65dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
list :
<activity
android:name="com.company.YesterdayActivity"
android:theme="@android:style/CustomTheme" >
</activity>
最佳答案
我还使用了操作栏夏洛克,并通过这种方法设置标题位置。您可以设置自定义 TextView 并将其重力设置为中心。使用下面的方法并告诉我。
private void setHeader(){
LayoutInflater linflater = (LayoutInflater)MainAccountActivity.context.getSystemService(MainAccountActivity.context.LAYOUT_INFLATER_SERVICE);
View GalleryTitleView = linflater.inflate(R.layout.layout_header, null);
galleryTitleTv = (TextView) GalleryTitleView
.findViewById(R.id.GalleryTitleTv);
galleryTitleTv.setText(ITWAppUIConstants.TAB_AGENDA);
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
GalleryTitleView.setLayoutParams(lp);
getSupportActionBar().setCustomView(GalleryTitleView);
}
这是我使用的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/GalleryTitleTv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dip"
android:textColor="@color/white"
android:textSize="20dip"
android:textStyle="bold" />
关于android - Android 操作栏中 Activity 的中心标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17605282/