gpt4 book ai didi

java - Android工具栏的文字大小和样式

转载 作者:数据小太阳 更新时间:2023-10-29 03:00:56 27 4
gpt4 key购买 nike

我正在开发支持多屏幕的应用程序。我已经根据设备大小完成了所有剩余布局,但我无法增加相同的操作栏/工具栏大小。它在 10 英寸平板电脑中看起来很小。如何增加工具栏文本的大小?

我的样式 XML 如下所示

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">

</style>


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen" parent="noActionBar">
<item name="android:windowFullscreen">true</item>
</style>
<style name="noActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="OptionDialog" parent="Theme.AppCompat.Dialog.Alert">

<item name="colorAccent">#C5CAE9</item>
<item name="android:background">#3F51B5</item>
<item name="android:textColor">?android:attr/textColorPrimaryInverseDisableOnly</item>
</style>


<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="SelectableItemTheme">
<item name="colorControlHighlight">#888888</item>
</style>

<style name="SelectableItemBackground">
<item name="android:theme">@style/SelectableItemTheme</item>
<item name="android:background">?attr/selectableItemBackground</item>
</style>


<style name="HomeTabTextStyle"
parent="TextAppearance.Design.Tab">
<item name="android:textSize">35sp</item>
<item name="android:textStyle">bold</item>
</style>

<!-- Action Bar Style -->

我的包含工具栏的布局 xml 如下所示

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabTextAppearance="@style/HomeTabTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />


</android.support.design.widget.AppBarLayout>

我的 Java 代码如下所示

setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

setTitle("My App Name");

最佳答案

工具栏就像任何其他布局一样;这意味着您可以像这样在其中添加元素:

     <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:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="@color/colorText"
android:gravity="center|center_horizontal"
android:text="@string/title_activity_my_activity"/>

</android.support.v7.widget.Toolbar>

这将更改工具栏标题的标题大小;如你所愿。

我希望这可以帮助您实现目标!祝你好运。

更新

如果你想手动设置 Activity 标题,你可以像这样为 TextView 设置一个id:

<TextView
android:id="@+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="@color/colorText"
android:gravity="center|center_horizontal"
android:text="@string/title_activity_my_activity"/>

然后像往常一样,

TextView title = (TextView) toolbar.findViewById(R.id.title_text);
title.setText("New Title");

希望对您有所帮助!

关于java - Android工具栏的文字大小和样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38380785/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com