SeekBar change gray color - android

I searched a lot but could not find.
I want the basic gray color of SeekBar change to white.
All the examples I've found it just change the color of progress.
Can anyone help me?

Try creating progress.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/background_fill" />
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/progress_fill" />
</item>
Then in your seekbar declaration in xml set:
android:progressDrawable="#drawable/progress"

You can refer below link for creating Android components such as editext or spinner or seekbar with your own colors for your Android application. It will generate all necessary nine patch assets plus associated XML drawables and styles which you can copy straight into your project.
For ex. for your case you can go to this link and download the zip file for your new seekbar with custom color.
http://android-holo-colors.com

Here you go:
<androidx.appcompat.widget.AppCompatSeekBar
android:progressBackgroundTint="#color/gray"
android:progressTint="#color/white"

Ok, So, there are two things
You want to change Seekbar style through out the app
You want to change Seekbar style for specific screen
If want to change through out the app. Add this in your style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="seekBarStyle">#style/AppSeekBar</item>
</style>
<style name"AppSeekBar" parent="Widget.AppCompat.SeekBar">
<item name="android:thumb">#drawable/ic_launcher</item>
<item name="android:background">#drawable/app_seekbar_background</item>
</style>
</resources>
And that's it, all SeekBar in the app will start using this style.
If you want to change for specific screen. Add this in your style.xml
<resources>
<!-- your rest of code -->
<style name"AppSeekBar" parent="Widget.AppCompat.SeekBar">
<item name="android:thumb">#drawable/ic_launcher</item>
<item name="android:background">#drawable/app_seekbar_background</item>
</style>
</resources>
And in the your_layout.xml file add this
<!-- your rest of code for layout -->
<SeekBar
android:layout_width="100dp"
android:layout_height="40dp"
style="#style/AppSeekBar"
<!-- your rest of code for seek bar-->
/>
This should reflect your style.
And if you want to change anything else for you can come to this style.xml file and change, no need to change each and places you are using SeekBar

Related

Setting Background Drawable to Button in xml does not change the color Android Studio 4.2 preview

I have been doing this for years with no problem, when I need to create a button with curved corners I create a drawable with corners and a color and I use it as the background to the button I need to change, but since Android Studio 4.2 preview, it's not working any more. Can anyone help. Thanks.
Here is an example of how the drawable xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#EFB70E" />
<corners android:radius="12dp" />
</shape>
and I set that drawable as the background of my button.
In Material Design components, buttons have a default backgroundTint value set to colorPrimary that is why no matter what color you use in your button's background, it will be tinted blue(colorPrimary).
Just Add this line in the button's code : app:backgroundTint="#null"
And a better way to make your buttons round in material design:
In your themes.xml file add this :
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
</style>
Then if you want to apply round corners to all buttons in the app, add this line in your app's main theme :
<item name="shapeAppearanceSmallComponent">#style/ShapeAppearance.App.SmallComponent</item>
Otherwise, if you want to apply this style to specific button, add this line to it's code:
style="#style/Widget.App.Button"

How to get the default notification background color for custom notification in Lollipop?

I'm having an issue with the color of my custom notification background in Lollipop.
It's black where it should be white.
The textColor is OK:
I'm using
<resources>
<style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />
<style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent.Title" />
</resources>
Any idea how to use the device default theme color for custom notification ?
Your app's targetSdkVersion must be 21.
As Ahmed's answere, add another styles file in values-21 folder.
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
<style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />
</resources>
For whatever reason, there are new styles in Lollipop. Put this in values-v21/styles.xml:
<resources>
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title"></style>
<style name="NotificationText" parent="android:TextAppearance.Material.Notification"></style>
</resources>
Create folder values-v21/styles.xml and past the below code,
<style name="NotificationTitle" parent="#android:style/TextAppearance.StatusBar.EventContent.Title">
<item name="android:textColor">#android:color/black</item>
<item name="android:textStyle">normal</item></style>
To solve this, you have 2 options:
1) Target SDK 21, and custom notification will automatically use a white background
2) Copy your existing layout to layout-v21 folder and add android:background="#FFFFFFFF" to its root, like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#FFFFFFFF" >
...
</LinearLayout>
Works great for me.
I'm not sure what the theme of the background is but I just set the background of my custom layouts (small view and large view) to a dark colour in the xml. This then matches the pre-Lollipop notifications more closely.
I find it bizarre that the appearance of android:TextAppearance.StatusBar.EventContent.Title doesn't adjust to a dark colour for Lollipop when the standard notification colour is white!

How to change the color of TabText using styles?

I am using styles for customizing the appearance of tabs in my app. I have managed to change the color and appearance of the background of the tabs based on whether the tab is selected with no problems.
However, when I am trying to change the color of the TabText to white (#ffffff), nothing seems to be happening.
I am doing this by extending the parent#style/Widget.AppCompat.ActionBar.TabText and setting the android:textColor to my own color: #color/tab_text_color. I have followed the instructions and examples for doing this but the text color just seems to be unaffected.
All I want is for the text color of the tabs to be white all the time as it is only the background of the tabs that will change when selected. I have followed the way many examples do this but for some reason nothing is happening.
Would anyone be able to suggest what I am missing or the way to change the color of text in tabs in an xml style?
Thanks in advance.
The two files involved are below:
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">#drawable/actionbar_tab_indicator</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_tab_indicator</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/tab_text_color</item>
</style>
tab_text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#ffffff" />
</selector>
I managed to solve my problem, here is what was needed for anyone who is stuck on this in future:
Creating my own actionBarTabText style seems to be the right way to go. Even though I set the theme of the application in the AndroidManifest as: android:theme="#style/CustomActionBarTheme" , the actual text was being created in a TextView within a linear layout which meant that the style was not being applied to it.
This explains why the other style elements such as the tabs and actionbar backgrounds were being styled but the text was not as they were not created in the layout. To solve this, in my TextView I just set the style attribute to that of the "TabTextStyle" I had created in themes.xml.
I still do not fully understand why I had to apply the particular style manually even though it should have been set as part of the "CustomActionBarTheme" in the AndroidManifest. Anyway, this fix works so here is the code below:
<TextView
android:id="#+id/friend_tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:layout_gravity="center"
android:text="FRIENDS"
style="#style/TabTextStyle"/>

How to set custom color on selected/highlighted list-item in activatedBackgroundIndicator

Hello I am developing an app using ActionBarSherlock and Navigation Drawer. I have created an initial navigation drawer with actionBar Sherlock just like this:
Everything seems okay But I want to change default blue color of highlighted list-item with my custom color. I tried this link but it is not working. What I need to do to achieve custom highlight color?
Hello I have solved it for android OS version 11 and higher by applying style:
<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:activatedBackgroundIndicator">#drawable/activated_background</item>
</style>
activated_background in the drawable folder:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="#color/uva_color" />
<item android:state_selected="true" android:drawable="#color/uva_color" />
<item android:state_pressed="true" android:drawable="#color/uva_color" />
<item android:drawable="#color/default_color" />
</selector>
Color values in the values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="uva_color">#c31756</color>
<color name="default_color">#111</color>
</resources>
And set choicemode in the listview:
android:choiceMode="singleChoice"
And at last, send getBaseContext() to arrayApdater/your customAdapter as parameter instead of getApplicationContext().
mMenuAdapter = new MenuListAdapter(this.getBaseContext(), title, icon);
Also this link would help you.
Comment below if you face problem anywhere. I am ready to answer anytime, I don't want to let anyone getting trouble with this like me. Cheers!

how to change the color of the tabs indicator text in android?

how to change the color of the text indicator of tab? i can change the icon using selector tag refered the example. but cant to the text color. how?
Here is a new answer I found from Fred Grott (http://knol.google.com/k/fred-grott/advance-tabs/) after a little web searching.
This lets you set a selector for text color so a different color can be used when tab is selected or not. Which can be very useful if you are using a different background color for the tab if its selected. Of course you can also just throw in a plain color and not a selector.
final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.color.text_tab_indicator));
Where R.color.text_tab_indicator is a selector xml file located in your res/drawable folder.
In other words, the indicator text really is a TextView which is retrievable via the View object which can be accessed from the TabWidget object.
Take a look at Fred's examples for more info and context regarding the variable declarations as well as other tricks.
Style it
in your custom theme change
<item name="android:tabWidgetStyle">#android:style/Widget.TabWidget</item>
and
<style name="Widget.TabWidget">
<item name="android:textAppearance">#style/TextAppearance.Widget.TabWidget</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
<style name="TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#android:color/tab_indicator_text</item>
</style>
Danny C's answer is 100% correct.I just wanted to add something to it to make a complete answer with resource file.
The text_tab_indicator under res/color file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:textColor="#color/text_tab_selected"
android:state_selected="true" />
<item android:textColor="#color/text_tab_unselected"
android:state_selected="false" />
</selector>
And this text_tab_unselected & text_tab_selected will look like this under colors/values folder
<resources>
<color name="text_tab_selected">#ffffff</color>
<color name="text_tab_unselected">#95ab45</color>
After that finally add Dannyy's answer in tab class file
final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.color.text_tab_indicator));
The change in color can also be stated without using java - which is probably better.
I made changes to the text_tab_indicator (notice textColor was changed to 'color'):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#color/text_tab_selected" />
<item android:state_selected="false" android:color="#color/text_tab_unselected" />
</selector>
Set the style of the TabWidget to point to a specific style in your xml code:
<TabWidget
...
style="#style/TabText"
/>
Declare your text_tab_indicator located in /res/color as you desired color in the style
<style name="TabText">
<item name="android:textColor">#color/tab_text_color</item>
</style>
It worked like a charm (for me).
Cheers,
Randall

Categories

Resources