Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toolbar: small title text in landscape mode

I'm testing the new Toolbar and AppCompat theme on Android and ran into a problem. My toolbar title text looks normal-sized on portrait mode but it became rather small on landscape mode although I didn't do anything in the code to change the title's text size. Here are the screen shots:

PortraitLandscape

activity_main.xml:

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. --> <LinearLayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     xmlns:app="http://schemas.android.com/apk/res-auto"     tools:context="com.techfunmyanmar.jujaka.ui.MainActivity">      <android.support.v7.widget.Toolbar         android:id="@+id/main_toolbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="?attr/colorPrimary"         app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"         app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />      <android.support.v4.widget.DrawerLayout         android:id="@+id/drawer_layout"         android:layout_width="match_parent"         android:layout_height="match_parent">          <!-- As the main content view, the view below consumes the entire              space available using match_parent in both dimensions. -->         <FrameLayout             android:id="@+id/container"             android:layout_width="match_parent"             android:layout_height="match_parent" />          <!-- android:layout_gravity="start" tells DrawerLayout to treat              this as a sliding drawer on the left side for left-to-right              languages and on the right side for right-to-left languages.              If you're not building against API 17 or higher, use              android:layout_gravity="left" instead. -->         <!-- The drawer is given a fixed width in dp and extends the full height of              the container. -->         <fragment             android:id="@+id/navigation_drawer"             android:name="com.techfunmyanmar.jujaka.ui.NavigationDrawerFragment"             android:layout_width="@dimen/navigation_drawer_width"             android:layout_height="match_parent"             android:layout_gravity="start"             tools:layout="@layout/fragment_navigation_drawer" />     </android.support.v4.widget.DrawerLayout> </LinearLayout> 

styles.xml:

<resources>     <!-- Base application theme. -->     <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">         <item name="windowActionBar">false</item>          <!-- Customize your theme here. -->         <item name="colorPrimary">@color/primary</item>         <item name="colorPrimaryDark">@color/primary_dark</item>         <item name="colorAccent">@color/accent</item>      </style>      <!-- Main application theme. -->     <style name="AppTheme" parent="AppBaseTheme">      </style>      <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">         <item name="spinBars">true</item>     </style> </resources> 
like image 477
Nyein Chan Wynn Avatar asked Jan 20 '15 09:01

Nyein Chan Wynn


People also ask

How do I change the title text bar in android?

First, add a font file in the src/main/assets/fonts/ of your project. Then create variables for Toolbar and text title and call the method findViewById(). Create a new Typeface from the specified font data. And at last setTypeface in text title.

How do I change the size of my taskbar on android?

You can set the height here android:minHeight="? attr/actionBarSize" in your XML. Use height and not minHeight.

How do I center my toolbar title on android?

suggest use android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" instead. To keep using default styles for the customised TextView, try something like style="@style/TextAppearance.

How can I change the color of my toolbar title in android?

Go to the app > res > values > themes > themes. xml file and add the following line inside the <resources> tag. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar. This method sets the toolbar as the app bar for the activity.


1 Answers

I tried to set android:titleTextAppearance of the toolbar but the style wasn't being applied. Then I realized I'm using the AppCompat theme so I used app:titleTextAppearance and the style is now being applied. It looks like the small letters in landscape are a problem in the built-in AppCompat.Toolbar.Title style itself so I overrode it to set the font size manually. The final code:

Toolbar XML:

<android.support.v7.widget.Toolbar         android:id="@+id/main_toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:background="?attr/colorPrimary"         app:titleTextAppearance="@style/ToolbarTitle"         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"         app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

Toolbar Style:

<style name="ToolbarTitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">         <item name="android:textSize">20sp</item> </style> 
like image 179
Nyein Chan Wynn Avatar answered Nov 03 '22 17:11

Nyein Chan Wynn