我正在设计一个动作栏,我设计了一个自定义动作栏,但该客户动作栏中的问题是我使用了一个文本视图,我需要它作为中心。 这里是我的自定义操作栏的XML代码 -如何在android中创建文本视图中心?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:layout_height="50dp"
>
<TextView
android:id="@+id/title_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="20sp"
android:text="@string/app_name"
/>
</LinearLayout>
这里是使custome操作栏该活动我的Java代码。
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.customactionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#f8f8f8")));
Typeface fontt = Typeface.createFromAsset(getAssets(), "helvetica.ttf");
mTitleTextView.setTypeface(fontt);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
你没有使用自定义的操作栏的默认 – 2014-10-02 06:28:27
使用相对布局,而不是线性布局 – 2014-10-02 06:28:29
添加此到你的xml''android:gravity =“center”'为'TextView' – prabhakaran 2014-10-02 06:43:16