How to change the toolbar text size?
Use app:titleTextAppearance
:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="@+id/toolbar"
app:titleTextAppearance="@style/Toolbar.TitleText" />
and override the default title size in a custom style:
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>
Result:
Why can't I change toolbar textsize?
try using
app:titleTextAppearance="@style/Toolbar.TitleText"
instead of
android:titleTextAppearance="@style/Toolbar.TitleText"
as shown here
For centering gravity refer to this question and this question
Title text size of Toolbar
in all dimens.xml
<dimen name="myTextSize">xxxxxsp</dimen>
in values/style.xml
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">@dimen/myTextSize</item>
</style>
Change color and size of the title in Toolbar- Android
It's well explained here. Add this to your Toolbar:
app:titleTextAppearance="@style/Toolbar.TitleText"
And create a style for it:
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
How to change font,size of text and set text position center ToolBar Android?
If you're using androidx
don't use android.support.v7.widget.Toolbar
.
You have to use androidx.appcompat.widget.Toolbar
.
Create toolbar.xml
in res/layout.
Put this code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="yourToolBarBackgroundColor"
>
<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TestToolBar"
android:fontFamily="yourFont"
android:textSize="yourSizeOfText"
android:textColor="yourTextColor" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/activity_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Disable ActionBar in themes.xml:
<style name="Theme.YourProject" parent="Theme.MaterialComponents.DayNight.NoActionBar">
For night theme you have to do same thing in themes.xml(night)
Then in MainActivity.java in onCreate:
setContentView(R.layout.toolbar);
Change font size of Toolbar title in CollapsingToolbarLayout in android
Got answer from this link
mCollapsingToolbarLayout.setTitle(getTitle());
mCollapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
mCollapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
<style name="ExpandedAppBar" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">28sp</item>
<item name="android:textColor">#000</item>
<item name="android:textStyle">bold</item>
</style>
<style name="CollapsedAppBar" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">24sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:textStyle">normal</item>
</style>
<style name="ExpandedAppBarPlus1" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">28.5sp</item>
<item name="android:textColor">#000</item>
<item name="android:textStyle">bold</item>
</style>
<style name="CollapsedAppBarPlus1" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">24.5sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:textStyle">normal</item>
</style>
How to change Toolbar height and font size programmatically depending of text length
try this create custom toolbar like this
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Did you know"
android:id="@+id/myTitle"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
and use theme of your activity as NoActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView myTitle = (TextView) toolbar.findViewById(R.id.myTitle);
SwiftUI toolbar text size changes on appear
This bug is solved in iOS 16 beta.
Text Size and Style of Toolbar Android
Toolbar is like any other layout; that means you can add elements inside it like this:
<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>
This will change the title size of your toolbar title; as you wish.
I hope this helps you achieve your goal! Good luck.
UPDATE
If you want to manually set the activity title, you can set an id for the text view like this:
<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"/>
Then like usual,
TextView title = (TextView) toolbar.findViewById(R.id.title_text);
title.setText("New Title");
I hope this helps!
Related Topics
How to Change the Track Color of a Switchcompat
Multiple Selection in Custom Listview with Cab
How to Save File from Website to Sdcard
How to Populate Android Room Database Table on First Run
React Native Adb Reverse Enoent
Preferencefragmentcompat Has Padding on Preferencecategory That I Can't Get Rid Of
Admob Getting an Ad Response. Errorcode: 0 Failed to Load Ad:0
Using Enableautomanage() in Fragment
How to Keep Android Applications Always Be Logged in State
Display Huge Images in Android
One Onclickhandler for Multiple Buttons
Change Checkbox Value Without Triggering Oncheckchanged
Android How to Create Triangle and Rectangle Shape Programmatically
How to Have a Gridview That Adapts Its Height When Items Are Added