How To Change Action Bar Text Color - android

How can i change my action bar text color White to Black ? I don't want to use the Action Bar Sherlock .
Here Is My Code For Action Bar .
ActionBar ab = getActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ab.setCustomView(R.layout.actionbar);
ab.setDisplayHomeAsUpEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#33CCFF"));
ab.setBackgroundDrawable(colorDrawable);
Here is Custom View For Action Bar :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/title"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
Here style.xml :
<resources>
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.

Try this styles:
You can edit your TitleTextStyle inside of styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/black</item>
</style>
</resources>

Here is the styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style></resources>
thanx to rnoway

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/title"
android:textColor="#ffffff" // change the color code your wat , instead of #ffffff put youra
android:textSize="24sp" />
u can find the color codes from
http://www.w3schools.com/tags/ref_colorpicker.asp

Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:
getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"#000000\">" + getString(R.string.app_name) + "</font>"));

Related

How to customize default theme of radio button in android?

i want to change default theme of radio button to custom but it's not changing the theme. please help me out
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:radioButtonStyle">#style/radionbutton</item>
</style>
<!-- custom style -->
<style name="radionbutton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">#drawable/radiobutton_drawable</item>
</style>
radiobutton_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="#mipmap/radio_unselected" >
</item>
<item android:state_checked="true" android:drawable="#mipmap/radio_selected">
</item>
Declare custom style in your styles.xml file.
<style name="MyRadioButton" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/indigo</item>
<item name="colorControlActivated">#color/pink</item>
</style>
Apply this style to your RadioButton via android:theme attribute.
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"
android:theme="#style/MyRadioButton"/>
only if your activity extends AppCompatActivity
Finally, i found answer by myself
I just create custom layout and add to ListAdapter object
radiobuttonlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/checkedTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="#drawable/radiobutton_drawable"
android:gravity="center_vertical"
android:text="New CheckedTextView"
android:padding="#dimen/dp10"
android:textColor="#color/white" />
Java file code
ListAdapter listAdapter = new ArrayAdapter<String> (context,R.layout.radiobuttonlayout,aryStrLockscreens);
listview_lockscreen.setAdapter(listAdapter);
It's worked for me.
The radiobutton_drawable.xml has a missing </selector> tag in the end.
Plus you should do this to your radio button-
<RadioButton android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:id="#+id/radio"
style="#style/radionbutton"
android:layout_height="wrap_content"/>
Sure you can do it in the parent AppTheme just do the following:
First you will Use the MaterialTheme as your parent theme:
<style name="AppTheme" parent="Theme.MaterialComponents.*">
Then create your RadioButton style in res/values/styles
<style name="Widget.App.RadioButton" parent="Widget.MaterialComponents.CompoundButton.RadioButton">
<item name="buttonTint">#color/white</item>
//put any thing here
</style>
Add it to Parent AppTheme
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<item name="radioButtonStyle">#style/Widget.App.RadioButton</item>
</style>
Then Use it in your layout like:
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
/>
for more details about theming Theming RadioButton
Need to apply individual style to radio button
<RadioButton
android:layout_width="wrap_content"
style="#style/radiobutton_drawable"
android:layout_height="wrap_content"/>
You could add this to your styles.xml
<style name="Widget.Styles.Radio.RadioButton"
<item name="android:textAppearance">#style/ANY_TYPOGRAPHY_STYLE</item>
</style>
ANY_TYPOGRAPHY_STYLE is for example:
TextAppearance.MaterialComponents.Caption if you are using the Material theme
TextAppearance.AppCompat.Caption if you are using AppCompat theme.
OR any typography style you have created
Example:
<style name="TextAppearance.TypographyStyles.Body2" parent="TextAppearance.MaterialComponents.Body2">
<item name="fontFamily">#font/poppins_regular</item>
<item name="android:fontFamily">#font/poppins_regular</item>
<item name="android:textSize">14sp</item>
</style>
And use the radio button style as a style for the MaterialRadioButton or RadioButton
<com.google.android.material.radiobutton.MaterialRadioButton
style="#style/Widget.Styles.Radio.RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"/>

Android - ActionBar TitleText Color

Im trying to change the color of the text of my actionBar, I can modify the background when I use onlye the AppTheme but not the color of the title neither the backgroung when I create new theme.
Im trying to following this question and this tutorial but I cant do it, the text is always black.
I create the actionBar following the developers android tutorials.
This is my style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse" >
<item name="android:background">#color/actionbar_background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
My main Layout that has the actionBar, I used the new style I created
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.marcelo.notemuevas.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/CustomActionBarTheme"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:layout_below="#id/my_toolbar">
</RelativeLayout>
</RelativeLayout>
And in the manifest I try use both themes, AppTheme and CustomActionBarTheme but nothing works
android:theme="#style/CustomActionBarTheme" >
put this in your theme ;
<item name="textColorPrimary">#color/text</item>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
</resources>
There are few ways to change Actionbar/Toolbar Title color
First:- You can add this item in your theme or style (CustomActionBarTheme)
<item name="textColorPrimary">#color/text</item>
using this above line it will change title color for all Activities where you have used CustomActionBarTheme theme
Second:- Programmatically in your activity
getSupportActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + getString(R.string.yourTitle) + "</font>"));
Try my work around here. Sometimes it is strange that the color or any other properties of the toolbar are difficult to customize (rare cases ). So you can try the below code. It works for me.
Solution 1 :
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" >
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:text="Toolbar Title"
android:textColor="#android:color/white" //---- Apply your color here
android:textSize="18sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
Solution 2:
Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id._toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(Html.fromHtml(" <font color='#555555'> Your Title </font>"));
getSupportActionBar().setDisplayShowTitleEnabled(true);
check whether the above methods works for you..!!

Make color of icon in navigation drawer

I'm trying to learn Android, and I'm attempting to make a navigation drawer.
My goal is to achieve something like this:
But my result looks like this:
This is my style.xml:
</style>
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/md_deep_purple_500</item>
<item name="colorPrimaryDark">#color/md_deep_purple_700</item>
<item name="colorAccent">#color/md_white_1000_50</item>
</style>
<style name="ToolbarTheme" parent="AppTheme">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="NavigationViewTheme" parent="AppTheme">
<item name="textAppearanceListItem">#style/TextAppearance.AppCompat.Body2</item>
<item name="android:icon">#style/Theme.AppCompat.Light</item>
</style>
</resources>
This is my navigation_drawer_header:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="16dp"
android:gravity="bottom"
android:theme="#style/ThemeOverlay.AppCompat.Light"
>
</FrameLayout>
Can anyone suggest to me how these should be corrected?
This is because the NavigationView add tint to the icons.
To avoid this you can add
navigationView.setItemIconTintList(null);
You can add color state list. Get a look into this

How to remove background of action menu item?

I have got the following action menu:
As you can see all of these action menu items are having a
background. i guess it is the same background like the parent.
How can i remove this background?
My style.xml is the following:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorAccent">#color/accentColor</item>
<item name="android:textColorPrimary">#color/textcolorsecundary</item>
<item name="android:textColorSecondary">#color/textcolorsecundary</item>
<item name="android:actionModeBackground">#color/primaryColor</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:activatedBackgroundIndicator">#drawable/custom_background_listview_item</item>
</style>
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">#color/textcolorsecundary</item>
<item name="actionMenuTextColor">#color/textcolorsecundary</item>
<item name="android:textColorSecondary">#color/textcolorsecundary</item>
<item name="android:showDividers">beginning</item>
<item name="android:divider">#color/primaryColorDark</item>
<item name="android:background">#drawable/custom_background_blue</item>
</style>
<style name="AppTheme.Toolbar.PopupMenu" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:popupBackground">#color/primaryColor</item>
</style>
</resources>
My Toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:elevation="2dp"
android:focusable="false"
app:popupTheme="#style/AppTheme.Toolbar.PopupMenu"
app:theme="#style/AppTheme.Toolbar" >
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="#null"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
The following line is the problem
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">#drawable/custom_background_blue</item>
</style>
Since the above is applied not as style but as a theme (presumably via popupTheme attribute on your Toolbar element), all the widgets inside the toolbar inherit these settings. What you want is android:popupBackground instead of android:background.
Edit: OP stated the above is not sufficient. For styling toolbar's popup menu (not the toolbar itself) use the app:popupTheme attribute. The theme is going to be similar to this:
<style name="AppTheme.Toolbar.PopupMenu" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:popupBackground">#drawable/custom_background_blue</item>
</style>
You're setting the action background color explicitly in your style.xml same as the primary color.
<item name="android:actionModeBackground">#color/primaryColor</item>
Try removing this from your XML or changing it to a color that seems appropriate for your UI and it should work. If you don't choose to manually specify a color for the android:actionModeBackground, it will simple derive it's default value from the parent theme (in your case, Theme.AppCompat.Light.NoActionBar).

Why size of rating bar not decreasing?

I want to decrease the size of the rating bar, but I'm unable to do so. I have tried to apply on rating bar still there is no change on rating bar size.
Please help
Here is style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="ratingBar" parent="#android:style/Widget.RatingBar">
<item name="android:maxHeight">10dip</item>
<item name ="android:maxWidth">10dip</item>
</style>
</resources>
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="58dp"
style="#style/ratingBar" />
</RelativeLayout>
You need to set the drawable for the stars
<style name="RatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars</item>
<item name="android:minHeight">32dp</item>
<item name="android:maxHeight">32dp</item>
</style>
<style name="RatingBar.Small" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars_small</item>
<item name="android:minHeight">22dp</item>
<item name="android:maxHeight">22dp</item>
</style>

Categories

Resources