I created a custom actionbar so that I can add buttons to the actionbar. But now I need a way to display the title of the app on this custom actionbar. I have a temporary fix by adding a TextView to my custom actionbar but I don't want to be re-sizing it for different devices (such as tablets and phone). See is what it looks it so far:
我创建了一个自定义操作栏,以便我可以向操作栏添加按钮。但是现在我需要一种方法来在这个自定义操作栏上显示应用程序的标题。我通过向自定义操作栏添加TextView来进行临时修复,但我不想为不同的设备(例如平板电脑和手机)重新调整它。看看它到目前为止的样子:
This title is too small. I want it to match the size of the buttons. Here is my code for the custom actionbar xml:
这个标题太小了。我希望它与按钮的大小相匹配。这是我的自定义操作栏xml的代码:
actionbar_custom.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal" >
<ImageButton
android:id="@+id/btnBack"
android:background="?attr/actionBarItemBackground"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_keyboard_backspace_white_24dp" />
<TextView
android:id="@+id/customTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:scaleType="centerInside"
android:layout_toRightOf="@+id/btnBack"
android:text="App Title" />
<ImageButton
android:id="@+id/btnHelp"
android:background="?attr/actionBarItemBackground"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_help_white_24dp" />
</RelativeLayout>
Any suggestions? Let me know if more detail is required.
有什么建议?如果需要更多详细信息,请与我们联系。
1 个解决方案
#1
0
I added this line to the TextView
tag: android:textAppearance="?android:attr/textAppearanceMedium"
我将此行添加到TextViewtag:android:textAppearance =“?android:attr / textAppearanceMedium”
#1
0
I added this line to the TextView
tag: android:textAppearance="?android:attr/textAppearanceMedium"
我将此行添加到TextViewtag:android:textAppearance =“?android:attr / textAppearanceMedium”