[英]How to change size of title's text on Action Bar?
There is an ActionBar
on each Android 4.0 application, and it got a title.每个 Android 4.0 应用程序上都有一个ActionBar
,它有一个标题。 I need to make this size less.我需要缩小这个尺寸。 But I don't understand how I can do it, because ActionBar
doesn't provide public methods for it.但我不明白我该怎么做,因为ActionBar
没有为它提供公共方法。 Remark: I don't want to use custom views.备注:我不想使用自定义视图。
Actually, you can do what you want to customize the ActionBar.其实,你可以做任何你想做的自定义ActionBar。 It must be done through the Theme.它必须通过主题完成。 You can do something like this :你可以这样做:
<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>
You could always do something like this:你总是可以做这样的事情:
ActionBar actionBar = getActionBar();
actionBar.setTitle(Html.fromHtml("<small>YOUR TITLE</small>"));
on my system, res/styles AppTheme has a note saying在我的系统上, res/styles AppTheme 有一个注释说
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
and this is the style indicated in AndroidMainfest.xml.这是 AndroidMainfest.xml 中指示的样式。 I added我加了
<item name="android:textSize">15sp</item>
and it worked and I'd rather do this than a custom actionbar.它起作用了,我宁愿这样做而不是自定义操作栏。
I have followed this method to skip the creation of custom style:我已按照此方法跳过自定义样式的创建:
1) Create a layout file (titlebar.xml): 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>
Here set your required textSize.在这里设置您所需的 textSize。
2) MainActivity.java 2) MainActivity.java
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); //bellow setSupportActionBar(toolbar);
getSupportActionBar().setCustomView(R.layout.titlebar);
hope this helps.希望这可以帮助。
The text's size in Android ActionBar is standard . Android ActionBar 中文本的大小是标准的。
Since ICS, Android now develops a standard so that applications will (hopefully) follow the same UI guidelines and design principles.自 ICS 以来,Android 现在开发了一个标准,以便应用程序(希望)遵循相同的 UI 准则和设计原则。
http://developer.android.com/guide/practices/ui_guidelines/index.html http://developer.android.com/guide/practices/ui_guidelines/index.html
This is why you can't change it.这就是你不能改变它的原因。
However , if you still want to do so, you could use a custom Theme or maybe implement ActionBar (a fork) and modify its sources: https://github.com/johannilsson/android-actionbar to get maximum control.但是,如果您仍然想这样做,您可以使用自定义主题或实现 ActionBar(一个分支)并修改其来源: https : //github.com/johannilsson/android-actionbar以获得最大控制。
subtitle:"exsample"
XML 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"/>
JAVA爪哇
getSupportActionBar.setSubtitle("Sub Title");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.