这是我尝试但没有发生的事情
<style name="MyCustomTheme" parent="Theme.Freshchat.Light.DarkActionBar">
<item name="titleTextStyle">@style/Style1</item>
</style>
<style name="Style1" parent="@android:style/Widget.TextView">
<item name="android:textSize">12sp</item>
</style>
有关更多上下文,我正在使用Freshchat聊天窗口小部件,并希望更改标题和字幕字体大小。谢谢!
答案 0 :(得分:4)
试试这个你可以Toolbar
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextAppearance="@style/ToolbarTitleTheme"
app:subtitleTextAppearance="@style/ToolbarSubtitleTheme">
</android.support.v7.widget.Toolbar>
而不是在Style.xml中创建Style
<style name="ToolbarTitleTheme" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">20dp</item>
<<item name="android:textColor">#FFAA12</item>
<!-- include other attributes you want to change: textColor, textStyle, etc -->
</style>
<style name="ToolbarSubtitleTheme" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textSize">14dp</item>
<item name="android:textColor">#FFAA12</item>
</style>
答案 1 :(得分:2)
1&gt;创建名为titleview.xml
代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="20sp"
android:textColor="@android:color/white"
android:maxLines="1"
android:ellipsize="end"
android:text="" />
</RelativeLayout>
2&gt;在OnCreate方法中:
if(getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);
//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView) v.findViewById(R.id.title)).setText(this.getTitle());
((TextView) v.findViewById(R.id.title)).setTextSize(20);
//assign the view to the actionbar
this.getSupportActionBar().setCustomView(v);
}
3&gt;在Manifest文件中添加此行
android:label="@string/room_title"
答案 2 :(得分:1)
简单的方法是为操作栏创建 custom_action_bar.xml 布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/action_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You title"
android:textColor="#ff0"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/action_bar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your subtitle"
android:textColor="#ff0"
android:textSize="12sp" />
</LinearLayout>
然后,您必须按如下所示设置自定义操作栏的布局:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_action_bar);
}
使用此方法,您将能够轻松自定义操作栏。
答案 3 :(得分:0)
您可以按如下方式使用SpannableString
:
SpannableString s = new SpannableString(getResources().getString(R.string.manage_prescription));
s.setSpan(new TypefaceSpan(YourActivity.this, Constants.TOOLBAR_TITLE_FONT), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
并使用此SpannableString对象将标题设置为操作栏。