如何自动调整字体大小的基础上定向操作栏微调?基础上、字体大小、操作

2023-09-13 00:49:35 作者:知足常乐

我想把它放到一个微调操作栏中,就像在Gmail应用程序。所以,我创建了下面的布局。

I wanted to place a spinner in the action bar, just like in the Gmail app. So I created the following layout.

  <?xml version="1.0" encoding="utf-8" ?> 
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
  <TextView android:id="@+id/spinner_list_item_selected_header" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:textStyle="bold" 
android:gravity="center" 
android:text="Sales" /> 
      <TextView android:id="@+id/spinner_list_item_selected_text"  android:layout_width="match_parent"
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:textStyle="bold" 
android:gravity="center" 
android:text="" /> 
      </LinearLayout>

本微调,然后装上的标题栏使用以下code:

This spinner is then loaded on to the title bar using the following code:

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getActionBar().setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);

它正常工作,只是在横向模式下,该文本是不恰当的。在Gmail应用程序,字体大小会减少。 有没有办法自动根据方向调整字体大小?

推荐答案

//你需要使用dimens.xml价值观文件夹

//you need to use dimens.xml in values folder

<!-- Text size for action bar titles -->
    <dimen name="action_bar_title_text_size">18dp</dimen>
    <!-- Text size for action bar subtitles -->
    <dimen name="action_bar_subtitle_text_size">14dp</dimen>
    <!-- Top margin for action bar subtitles -->
    <dimen name="action_bar_subtitle_top_margin">-3dp</dimen>
    <!-- Bottom margin for action bar subtitles -->
    <dimen name="action_bar_subtitle_bottom_margin">5dip</dimen>

创建具有价值,土地多了一个文件夹

create one more folder with values-land

在dimens.xml

in that dimens.xml

 <!-- Text size for action bar titles -->
    <dimen name="action_bar_title_text_size">16dp</dimen>
    <!-- Text size for action bar subtitles -->
    <dimen name="action_bar_subtitle_text_size">12dp</dimen>
    <!-- Top margin for action bar subtitles -->
    <dimen name="action_bar_subtitle_top_margin">-2dp</dimen>
    <!-- Bottom margin for action bar subtitles -->
    <dimen name="action_bar_subtitle_bottom_margin">4dip</dimen>

编号:转到 /&LT; Android的SDK&GT; /平台/ Android为15 /数据/ RES 在这里,你可以发现这个

Ref: go to your /<android-sdk>/platforms/android-15/data/res here you can found this.