I got a ListView where the background is black. Now my problem is that the default ripple effect is also black is the user cant really see it.
How can I change the color of the Ripple Effect without be dependent on API level ? (I want to achieve a white color).
You can set this as your views background:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorAccent">
<item android:id="#android:id/mask">
<color android:color="#42ffffff" />
</item>
For more details see this question on stackoverflow:
What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)
And you can use this library for lower apis:
https://github.com/traex/RippleEffect
Simply way to do is define these two colors inside your colors.xml file
<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>
cheers.
Just add 'item: colorControlHighlight' with the desired color in your styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlHighlight">#color/white</item>
</style>
When using Theme.MaterialComponents.* theme the ripple color can be defined by
adding following line to i.e. Ouline Button style.
<item name="rippleColor">#color/outline_button_ripple_color</item>
Related
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"
This question is related to two other questions that I'll specifically name below. The difference being, that I specifically ask for a way to change the color without the use of the base AppTheme.
In the first related question, the proposed solution includes setting
<item name="colorAccent">#color/Color Name</item> in AppTheme
However, it also says to make a theme/style specifically for the TextInputLayout, which looks like this:
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/Color Name</item>
<item name="colorControlNormal">#color/Color Name</item>
<item name="colorControlActivated">#color/Color Name</item>
</style>
So the colorAccentis set twice. I tried this and came to the conclusion that the specific theme for the TextInputLayout is unnecessary, as I got the same result, with and without it. Only setting the colorAccent in the AppTheme is sufficient. This works but isn't necessarily what I want/need.
In the second related question, people suggest to, again, modify the AppTheme and setting colorAccent (and other attributes).
However, I don't find this solution right/satisfying. There should be a way to specifically change that one color without changing the style of the whole app, which the person posing the second question also criticizes in one of his/her comments.
So, what I am specifically looking for here, is a solution, in XML or programmatically, to specifically change the color of the floating hint/label and cursor of the TextInputLabel+TextInputEditText Combo. Basically the same behavior I'd get when setting colorAccent.
Is there a way to do this or did the SDK developers seriously make it only possible by setting colorAccent?
PS I realize that this might work with making a new Theme, inheriting from AppTheme and setting it to the activities that I want to have the specific color. However, as I said, thats not what I'm looking for.
Create a custom style like this:
<style name="myInputText">
<item name="android:textColor">#color/myColor</item>
<item name="android:textSize">#dimen/text_size</item>
...
</style>
Now, you can directly use this in TextInputLayout, no need to provide any parent in style or change your app theme.
<android.support.design.widget.TextInputLayout
android:textColorHint="#color/myColor"
app:hintTextAppearance="#style/myInputText"
android:layout_width="match_parent"
android:layout_height="50dp">
EDIT
This only changes the color of the floating label, not the cursor. To also change the cursor color, you need to create a drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="10dp"
android:width="2dp"/>
<solid android:color="#color/myColor"/>
</shape>
and add it to the style you use for the TextInputEditText, not the TextInputLayout.
<style name="Settings.TextInputEditText">
...
<item name="android:textCursorDrawable">#drawable/cursor</item>
</style>
Change you want to color in res/color - and your favorite color as define 3 color you can change effect
You can try to set the colorAccent for the views you want, only... Something like:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/AppThemeInputLayout" />
Then, in styles.xml
<style name="AppThemeInputLayout" parent="AppTheme">
<item name="colorAccent">#FF0000</item>
</style>
I guess this way you can change the colorAccent for specific views only (and not for whole app)
Let me know if that works for you.. Otherwise, I will delete this answer.
I'm trying to make underline line color change for EditText (it will be used for input's validation, so it must be able to change in runtime).
I'm using AppCompat library. The problem is that on API 21 and above, I see transparent black line (gray overlay), instead of bolded version.
How to make it the same as in API 16?
I used this code to change tint:
final Drawable originalDrawable = view.getBackground();
final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable);
DrawableCompat.setTint(wrappedDrawable, Color.RED);
setBackground(view,wrappedDrawable);
Solution found by adding these lines to my theme:
<item name="editTextStyle">#style/Base.V7.Widget.AppCompat.EditText</item>
<item name="editTextBackground">#drawable/abc_edit_text_material</item>
You should not change the background. It's better if you create a theme, and use theme colors (colorPrimary, colorAccent are the most important for widgets) to get the desired effect. Assign the theme to your EditText and enjoy. Note: you should use one of the AppCompat theme as base theme.
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/accent</item>
</style>
and in your colors.xml
<color name="primary">#ff0000</color>
<color name="accent">#00ff00</color>
I want to change a spinner's dropdown menu background color without changing the background color of the spinner itself (it's transparent). Is it possible?
Yep, it's possible. Use android:popupBackground on the Spinner in your XML or setPopupBackgroundResource(int) in code.
To change the background color of the drop-down list, add android:colorBackground parameter to the theme in your styles.xml
Code:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:colorBackground">#ff0000</item>
</style>
Thus, the overall style is preserved: the effect when pressed, rounded corners, etc.
Screenshot:
When using Material Design 3 responsible attribute is:
<item name="colorSurface">#color/foo</item>
I am using AutoCompleteTextView in my android application. I am using Theme.Light as my default theme for my application.
Here is how my AutoCompleteTextView look like
Now, I want to change the BLUE color border of that AutoCompleteTextView to some other color ,for different selection, keeping the border style as it as. I dont want full border. How to do that?
You can try like this..
see http://www.androidworks.com/changing-the-android-edittext-ui-widget for details
For other theme implementation go for this way
In your manifest in application
android:theme="#style/firsttheme"
IN res/values you can define theme.xml
<resources>
<style name="firsttheme" parent="#android:style/Theme" >
<item name="android:_DEFAULT_BASE_COLOR_1">#XXXXXX</item>
<item name="android:windowNoTitle">true</item>
... .
</style>
</resources>
For more info theme
You can use Holo Colors to tint it. It generates the 9-patchs and the styles.