[英]How to change size of title's text on Action Bar?
每個 Android 4.0 應用程序上都有一個ActionBar
,它有一個標題。 我需要縮小這個尺寸。 但我不明白我該怎么做,因為ActionBar
沒有為它提供公共方法。 備注:我不想使用自定義視圖。
其實,你可以做任何你想做的自定義ActionBar。 它必須通過主題完成。 你可以這樣做:
<style name="Theme.YourTheme" parent="android:style/Theme">
<item name="android:actionBarStyle">@style/Theme.YourTheme.Styled.ActionBar</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar">
<item name="android:titleTextStyle">@style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="@android:style/Widget.TextView">
<item name="android:textSize">12sp</item>
</style>
你總是可以做這樣的事情:
ActionBar actionBar = getActionBar();
actionBar.setTitle(Html.fromHtml("<small>YOUR TITLE</small>"));
在我的系統上, res/styles AppTheme 有一個注釋說
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
這是 AndroidMainfest.xml 中指示的樣式。 我加了
<item name="android:textSize">15sp</item>
它起作用了,我寧願這樣做而不是自定義操作欄。
我已按照此方法跳過自定義樣式的創建:
1)創建布局文件(titlebar.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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/action_bar_title"
android:text="@string/app_name"
android:textColor="@color/colorPrimary"
android:textSize="24sp" />
</LinearLayout>
在這里設置您所需的 textSize。
2) MainActivity.java
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); //bellow setSupportActionBar(toolbar);
getSupportActionBar().setCustomView(R.layout.titlebar);
希望這可以幫助。
Android ActionBar 中文本的大小是標准的。
自 ICS 以來,Android 現在開發了一個標准,以便應用程序(希望)遵循相同的 UI 准則和設計原則。
http://developer.android.com/guide/practices/ui_guidelines/index.html
這就是你不能改變它的原因。
但是,如果您仍然想這樣做,您可以使用自定義主題或實現 ActionBar(一個分支)並修改其來源: https : //github.com/johannilsson/android-actionbar以獲得最大控制。
subtitle:"exsample"
XML
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:subtitle="subTitle"
app:title = "Title"
android:tag="dff"/>
爪哇
getSupportActionBar.setSubtitle("Sub Title");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.