[英]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.