Я пытаюсь с нескольких часов сосредоточить свой заголовок в панели действий по горизонтали. Это мой код:Текстовое изображение в центре Android в пользовательском ActionBar, используя линейный график горизонтально и вертикально
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/activityTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="20sp"
android:textColor="#FFFFFF" />
</LinearLayout>
и это мой onCreate()
код в моем activity
:
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.custom_action_bar, null);
Typeface tf = Typeface.createFromAsset(getAssets(),"font/myfont.ttf");
((TextView)v.findViewById(R.id.activityTitle)).setTypeface(tf);
((TextView)v.findViewById(R.id.activityTitle)).setText("Test");
getActionBar().setCustomView(v);
getActionBar().setDisplayShowHomeEnabled(false);
Значок ActionBar является спрятался и название в правильном шрифт, но только по центру по вертикали , но не горизонтально. Как я могу это сделать?
вы пробовали настройки ширины TextView в match_parent, а затем добавить гравитацию атрибут TextView? –
http://stackoverflow.com/questions/12387345/how-to-center-align-the-actionbar-title-in-android – zgc7009
@ zgc7009 этот ответ работает один, но не вместе с моим соглашением изменить шрифт бар действия – Maddy