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>
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
I have created my own custom view and added it to action bar :
Please take a look on below code :
How to set custom view to ActionBar ?
public static ActionBar setCustomActionBar(Activity activity, ActionBar actionBar, String title) {
if (actionBar != null) {
ViewGroup actionBarLayout = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.custom_actionbar, null);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
actionBar.setBackgroundDrawable(new ColorDrawable(activity.getResources().getColor(R.color.actionbar_grey)));
TextView actionBarTitle = (TextView) actionBarLayout.findViewById(R.id.text_actionbar_title);
Typeface airplaneTypeface = Typeface.createFromAsset(activity.getAssets(), "fonts/Exo-Regular.otf");
actionBarTitle.setText(title);
actionBarTitle.setTypeface(airplaneTypeface);
// SpannableString s = new SpannableString(title);
// s.setSpan(new TypefaceSpan(activity, "fonts/airplane.ttf"), 0, s.length(),
// Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// actionBar.setTitle(s);
}
return actionBar;
}
custom_actionbar.xml file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/actionbar_grey"
android:padding="@dimen/actionbar_padding">
<ImageView
android:id="@+id/img_up_indicator"
android:layout_width="@dimen/actionbar_icon_width"
android:layout_height="@dimen/actionbar_icon_height"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/text_actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/img_up_indicator"
android:layout_toRightOf="@+id/img_up_indicator"
android:paddingLeft="@dimen/actionbar_title_left_padding"
android:paddingStart="@dimen/actionbar_title_left_padding"
android:text="@string/app_name"
android:textColor="@color/logo_blue"
android:textSize="@dimen/actionbar_title_text_size" />
</RelativeLayout>
How to use method :
setCustomActionBar(this, getActionBar(), getResources().getString(R.string.title_actionbar_home));
This is a sample that shows how to create custom view and set it to actionbar.
You can modify it as per your requirement.
Note : Here I used my resources that I did not provided you can modify as you wish.
Thanks.!!
try to add this
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
for font size
<style name="TextAppearance.Medium">
<item name="android:textSize">18sp</item>
</style>
<style name="TextAppearance.Small">
<item name="android:textSize">14sp</item>
</style>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.