Is there a way to change the ripple colour of a control programmatically? Specifically, i want to be able to fetch the theme colours from an API and apply them to the whole application. From several answers around, i have learned that android doesn't allow to change the theme dynamically, so I set to implement my own theming.
One thing remains to be changed, the ripple colour:
Is there a way to change this dynamically (programatically) for
a single control?
EDIT: Specifically, I want to apply this to MenuItems inside a NavigationView and children clickable RelativeLayouts views of a ListView.
Is there a reasonable way to do it for the whole application? Like a rough equivalent of changing colorControlHighlight ?
With a MaterialButton you can use:
button.setRippleColor(ContextCompat.getColorStateList(this,R.color.selector));
Related
I'm trying to change the default black color of the pull to refresh arrow to a Material You dynamic color (for instance, the user's primary color based on their wallpaper). It doesn't seem to be possible to do over XML, and I tried over Kotlin but it wasn't pulling the dynamic color. I know that for SwipeRefreshLayout, you have to use either setColorSchemeColors() or setColorSchemeResources(), but I can't seem to figure out how to pull the dynamic colors.
SmartRefreshLayout.setDefaultRefreshHeaderCreater((context, layout) -> {
layout.setPrimaryColorsId(R.color.main_blue, android.R.color.white);
return new ClassicsHeader(context);
});
Is there a way of changing the color of the Spinner control?
For example, Android 6 will render text with an arrow. I need to change the color of that arrow.
The change should apply to any version of android.
For example, Android 4 has underline with corner triangle. I have seen some approaches where you replace the icon that is being drawn, but that solution would not work for me. I need to change the color of the default icon.
Update
I have found how to apply style on Android Spinner using styles.xml,
<item name="android:spinnerStyle">#style/SpinnerItem</item>
but I cannot find what is the correct style to apply for the icon color to change.
It turns out, there is no nice way of doing this. It is possible to change the images used for the spinner, but then I would need to provide different set of images for each version, and also have conditionals / logic on the android code, to specify which set should be used based on version.
I want to programmatically change the text color of all ListPreference in my PreferenceActivity, after the layout is constructed (so after onCreate). Basically I want to be able to toggle all text between black and white.
I've tried having two themes for both colors, but that requires to restart the activity to toggle between themes. I don't want that.
Can someone come up with a solution to this problem?
I guess the answer to my question is that there is no way to do what I wanted. I ended up using two themes for both colors, even though changing the theme will apply after restarting the activity.
I need to eliminate the gap between buttons in a layout. I'm doing it by setting background color for a style and applying that style to my buttons. This eliminates the highlighting upon press, which I of course need. Here is a solution to this problem, but it requires extra actions to be taken with Java code. Can I make it statically, only with XMLs?
Also, if there is any other way to remove the gap without changing the other aspects of button's appearance - please suggest. The only requirement is it should be done with XML (however, if no other options exist, I can inherit Button class).
You can use StateList xml for background of your button
The problem : I've changed my app's background color to white, and now I cannot see the ExpandableListView's group indicator anymore.
ExpandableListView has methods to change text color, background color, and divider color, but nothing I can see for the group indicator color.
I do not want to provide custom drawables, I just want to change the color of the drawables that are provided by Android, programmatically.
I feel there must be some simple way to do this.
You will have to use custom drawables here. You can't change the android drawables provided by Android.