Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change my action bar text color and font size in android

Tags:

android

i am new to android how to change my app name text color and font size ,my default text color was black i want change it to White color and increase my font size please any one help me

style.xml

my default text color was black i want change it to White color

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
    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">        
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
    <item name="android:actionBarTabTextStyle">@style/ActionBarTabText</item>
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    <item name="android:actionBarTabStyle">@style/tabStyle</item>
    <item name="android:actionBarDivider">@null</item>
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#029C7A</item>        
</style>

<style name="ActionBarTabText" parent="@android:style/Widget.Holo.Light.ActionBar">       
    <item name="android:textColor">#CFCFC4</item>
    <item name="android:gravity">center</item>
</style> 

<style name="MyActionBarTitleText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>
</style>

<style name="tabStyle" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:tabStripEnabled">false</item>    
</style>
</resources>
like image 731
Swamy Veera Avatar asked Nov 01 '25 23:11

Swamy Veera


1 Answers

Using AppCompat Theme, it can be done in this way. Define a custom style in styles.xml as follows:

<style name="CustomToolbarTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="actionMenuTextColor">add_colour_your_choice</item>
        <item name="android:textColorSecondary">add_colour_your_choice</item>
        <item name="android:textSize">30sp</item>
    </style>

Then in the layout of the activity where you wish to change the action bar colour add a toolbar:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/white"
        android:elevation="0.5dp"
        android:theme="@style/CustomToolbarTheme"/>

And lastly in the java file of the activity, add the following lines to onCreate after setContentLayout:

Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Note: For this to work, you will have to add:

compile 'com.android.support:appcompat-v7:22.2.1'

to your build.gradle(module:app) under dependencies. (There are two dependencies, one under buildscipt and one at the end. ADD the line to the one AT THE END

like image 102
Anuraag Baishya Avatar answered Nov 03 '25 14:11

Anuraag Baishya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!