How to change ActionBarSherlock Tab Text color? - android

adapter.addTab(getSupportActionBar().newTab().setText("Tab-1"),
Tab1.class, null);
adapter.addTab(getSupportActionBar().newTab().setText("Tab-2"),
Tab2.class, null);
adapter.addTab(getSupportActionBar().newTab().setText("Tab-3"),
Tab3.class, null);
As of now every Tab has its TextColor as white. I want it to be grey when not selected and white on selected. So, how can i change the text color in onTabSelected or onTabUnselected.
Or should i go with setCustomView for the tab?? Here again the TextSize and all needs to be taken care of
<style name="my_ActionBarTabStyle" parent="#style/Widget.Sherlock.ActionBar.TabView">
<item name="background">#drawable/tab_indicator_ab_wicfy</item>
<item name="android:background">#drawable/tab_indicator_ab_wicfy</item>
<item name="android:textColor">#color/black</item>
</style>
i tried to use
<item name="textColor">#color/black</item>
but it gives me error that textColor is not a valid attribute
Thank You

You should not change text color from the code. Use color state list resource instead.
Define the color selector in resources. Define a xml file in res/color/ directory. The file will contain:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- use when selected -->
<item android:state_selected="true" android:color="#fff" />
<!-- otherwise use -->
<item android:color="#888" />
</selector>
And then set the text color in a style:
<item name="android:textColor">#color/my_color_selector</item>
Edit:
You have to set the text color in the right place in the styles! Set the textColor in (android:)actionBarTabTextStyle. The theme has to contain:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<!-- define text style for tabs -->
<item name="actionBarTabTextStyle">#style/MyTabTextStyle</item>
<item name="android:actionBarTabTextStyle">#style/MyTabTextStyle</item>
...
</style>
Then set the text color in the tab text style:
<style name="MyTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText" >
<item name="android:textColor">#color/my_color_selector</item>
</style>

Related

Using android:autoCompleteTextViewStyle in theme.xml

So I have the following app theme:
<!-- Base application theme. -->
<style name="Theme.Base.App" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/DeepSkyBlue</item>
<item name="colorPrimaryVariant">#color/DeepSkyBlueVariant</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/white</item>
<!-- Background color of the entire window/screen-->
<item name="android:windowBackground">#color/GhostWhite</item>
<!-- This defines the default style for the text-input layouts: outlined
In case there is mixture of text-input layouts
e.g. exposed dropdown and outlined, then the exposed dropdown style must be defined in the according layout file
-->
<item name="textInputStyle">
#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox
</item>
<!-- This doesn't work. Neighter the textSize nor the textColor get changed....
-->
<item name="android:autoCompleteTextViewStyle">
#style/AutoCompleteTextViewMediumStyle
</item>
</style>
<style name="AutoCompleteTextViewMediumStyle" parent="Widget.AppCompat.AutoCompleteTextView">
<item name="android:textSize">#dimen/text_medium</item>
<item name="android:textColor">#color/design_default_color_error</item>
</style>
And my example fragment layout looks like this:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/layout_margin_default"
android:hint="#string/vehicle_type"
android:labelFor="#id/autocomplete_textview_vehicle_type"
app:startIconDrawable="#drawable/baseline_commute_24">
<AutoCompleteTextView
android:id="#+id/autocomplete_textview_vehicle_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
What I want basically is to set the textsize of every appearing AutoCompleteTextView to lets say 14sp and the TextInputLayout should be outlined.
The issue is that the style item android:autoCompleteTextViewStyle doesn't affect any AutoCompleteTextView whatsoever. However, the funny thing is that the style item textInputStyle work's like a charm, as the default TextInputLayout would appear in outlined form without defining the style in the fragment layout file.
So my question ist:
Could it be that the style item: android:autoCompleteTextViewStyle is deprecated or that the style of the AutoCompleteTextView must be defined directly inside the layout file?
If u want to change the text size, text color or whatsoever, overriding the theme for the TextInputLayout is the way to go.
Example:
<item name="textInputStyle">
#style/TextInputThemeStyle
</item>
<style name="TextInputThemeStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">#style/ThemeOverlay.Material3.TextInputEditText.OutlinedBox.ThemeStyle</item>
</style>
<style name="ThemeOverlay.Material3.TextInputEditText.OutlinedBox.ThemeStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:textSize">your text size.</item>
<item name="android:textColor">your text color</item>
</style>

Style Material Checkbox/Compound ripple color

I am trying to style CompoundButton.CheckBox using official material.io tutorial:
<style name="Widget.App.CheckBox" parent="Widget.MaterialComponents.CompoundButton.CheckBox">
<item name="buttonTint">#color/button_tint</item>
</style>
and in color/button_tint.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color=">#color/shrine_pink_900" android:state_checked="true"/>
<item android:alpha="0.38" android:color="#color/shrine_pink_100" android:state_enabled="false"/>
<item android:color="#color/shrine_pink_100"/>
</selector>
What I cannot style is the ripple effect color when checked checkbox is pressed:
I see that this color is the default green with transparency and I need to use blue one. Tried to play with checkbox states in selector but without luck.
Official documentation: https://material.io/develop/android/components/checkboxes
Try to override your checkbox theme like this:
first, declare this in your style:
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
<!-- Customize your color as you want here -->
<item name="colorControlNormal">#ADB6AF</item>
<item name="colorControlActivated">#F7F13D</item>
<item name="colorControlHighlight">#F73D</item>
</style>
then apply it to your checkbox:
<CheckBox
...
android:theme="#style/MyCheckBox"/>

SwitchCompat change color

I need to change SwitchCompat's track color.
I've tried this, but it didn't worked for me.
This is code of my XML file
<android.support.v7.widget.SwitchCompat
android:id="#+id/sc_push"
style="#style/switchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="#style/switchStyle"
app:theme="#style/switchStyle" />
and this is my style.xml file
<style name="switchStyle">
<item name="colorControlActivated">#color/red</item>
<item name="android:colorForeground">#color/gray</item>
</style>
What seems the problem?
In addition, I can't change the activity's color or base application's color. I have to change color for this single view.
Try this code.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<!-- Active thumb color & Active track color(30% transparency) -->
<item name="colorControlActivated">#color/theme</item>
<!-- Inactive thumb color -->
<item name="colorSwitchThumbNormal">#color/grey300</item>
<!-- Inactive track color(30% transparency) -->
<item name="android:colorForeground">#color/grey600</item>
...
</style>
The better way to do it would be,
Create new resource file as below, switch_track_color.xml, using selector tag.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#15A215" android:state_checked="true"/>
<item android:color="#BAC7CB" android:state_checked="false"/>
</selector>
Use this in style for SwitchCompat.
<style name="SwitchStyle">
<item name="thumbTint">#ffffff</item>
<item name="trackTint">#color/switch_track_color</item>
</style>

Theaming and style in Android

I style a theme using Android asset studio. and i set my app theme in my manifest file.
here my all layouts background color is white i want to change that into some other color. i need to mention my all layout background color in my Style.xml...
how we can do that...
<style name="Theme.Jwellers" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background</item>
<item name="android:popupMenuStyle">#style/PopupMenu.</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="android:actionDropDownStyle">#style/DropDownNav</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid</item>
<item name="android:actionModeBackground">#drawable/cab_background_top</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.mytheme.Widget</item>
</style>
If you have the color saved as a drawable just add
<item name="android:background">#drawable/drawableNameOfColor</item>
That should make the background color whatever you have assigned to the drawable drawableNameOfColor

Change background color of ActionBarSherlock programmatically

I have an ActionBarSherlock on my form. I'm reading style information at runtime. One of the pieces of style is the background color of the ActionBar. How can I change this at runtime? The color can be any RGB value.
Maybe this help : How to set title color in ActionBarSherlock? via style
or getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak)); via programmatically
With the theme
// add theme in app
<application android:theme="#style/MainTheme"></application>
// MainTheme
<style name="MainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
// MainThemeGreen
<style name="MainThemeGreen" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MainTheme.ActionBarStyle</item>
</style>
// ActionBar
<style name="MainTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/bg_green_actionbar</item>
<item name="android:titleTextStyle">#style/MainTheme.ActionBar.TitleTextStyle</item>
</style>
// Text style
<style name="MainTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/White</item>
</style>
// bg_green_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#ff74af3b" />
</shape>
</item>
</layer-list>
After this you can change Theme on fly: setTheme(R.styles.MainThemeGreen);
One way:
mSupportActionBar = getSupportActionBar();
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456));
where 0xff123456 is your required ARGB integer.
I just used below Code
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#00853c")));
it changed the bg color. Hope, it helps.

Categories

Resources