0
A
回答
0
0
在Java代码中
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#2B1C27")));
LayoutInflater inflater = LayoutInflater.from(this);
View v = inflater.inflate(R.layout.titleview_2, null);
TextView actionbar_title = (TextView)v.findViewById(R.id.actionbar_title);
actionbar_title.setTypeface(you can set your font here also.);
actionBar.setCustomView(v);
XML文件中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/actionBar"
android:paddingTop="7dp"
android:orientation="horizontal"
android:background="#9B66AB">
<TextView
android:id="@+id/actionbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical"
android:padding="8dp"
android:text="@string/appTitle"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_centerVertical="true"
/>
</RelativeLayout>
它会工作。
EDITED
getSupportActionBar().setTitle((Html.fromHtml("<font face=\"Times New Roman\">" + getString(R.string.title) + "</font>")));
1
您可以自定义工具栏。下面是代码快照
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
,然后你可以在你的java类(活动或片段)访问toolbar_title并设置自定义字体样式。
+0
这个解决方案对我来说是完美的。 –
-1
你可以尝试以下方法: -
动作条动作条= getSupportActionBar();
actionBar.setTitle(“New Title”);
0
“Android O引入了一项新功能,XML中的字体”。您现在可以制作自定义工具栏并使用
android:fontFamily="@font/lobster"
XML标记。您需要将字体添加到recources/font文件夹。欲了解更多信息,请参阅https://developer.android.com/preview/features/working-with-fonts.html
相关问题
- 1. 更改操作栏标题字体和颜色
- 2. 更改操作栏图标
- 3. 更改操作栏标题颜色
- 4. 如何更改操作栏menuitem的字体?
- 5. 如何更改我的标题操作栏(片段)?
- 6. 如何更改代码中的操作栏标题颜色
- 7. 更改操作栏上的图标
- 8. 如何在Xamarin中更改操作栏标题颜色android
- 9. 操作栏和更改图标
- 10. 如何更改标题栏图标?
- 11. 如何更改导航栏的字体?
- 12. FragmentStatePagerAdapter /更新操作栏标题
- 13. 如何改进操作栏
- 14. 如何适应更多的操作标签栏+导航栏?
- 15. 为什么我无法更改我的操作栏的标题?
- 16. 如何更改UIImagePickerController导航栏字体?
- 17. 更改导航栏字体
- 18. 更改我的自定义操作栏标题
- 19. 更改Android中的特定操作栏标题
- 20. 更改操作栏标题的颜色Android
- 21. 操作栏图标比操作栏更大并且被裁剪
- 22. 如何更改操作栏中的选项菜单图标?
- 23. 如何更改操作栏中的选项菜单图标?
- 24. 如何更改Ionic 2中的标题栏/导航栏
- 25. 导航栏标题更改
- 26. 更改标题栏中
- 27. 如何更改回窄和更改操作栏中的颜色
- 28. Android操作栏标题 - 更改背景颜色
- 29. 如何向操作添加/更改Android Studio工具栏图标?
- 30. 更改支持操作栏的高度
可以发布您的XML代码? –