How to auto adjust font size in the action bar spinner based on orientation?

后端 未结 2 561
南笙
南笙 2020-12-10 19:16

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

  

        
相关标签:
2条回答
  • 2020-12-10 19:30

    They best way is to know the orientation of the device when the activity is started and use a layout depending on it.

    If portrait setContentView(R.layout.layout_with_bigfont);

    If lanscape setContentView(R.layout.layout_with_smallfont);

    otherwise you need to set the font for that View (in this case TextView) alone dynamically using setTextSize(xdp) instead of using 2 different layouts for different orientations

    0 讨论(0)
  • 2020-12-10 19:35

    //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

    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>
    

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

    0 讨论(0)
提交回复
热议问题