I need to change button style from "contained" to "outlined" at runtime.
For now the only way I've found to create an outlined button is to set its style to ?attr/materialButtonOutlinedStyle.
Unfortunately I haven't found a way to change the style at runtime, is it possible?
Is there any way to get this effect?
As a view with text inside, it should have "setTextAppearance" function. It's not the ideal option but may help. Also can be useful to look on https://github.com/airbnb/paris.
Related
I have colors of text and button come dynamic form backend,
I need to change this color of text dynamically when change happens in backend all at time.
I could make it manual
textView.setTextColor(getResources().getColor(R.color.text_color));
Is there a way to change group of text color dynamically or must set every text color manually in code?
I searched for how to change theme colors dynamically at run time and i found this answer this answer.
But I also search again and I found this github
but it doesn't work on Android Marshmallow (6.0+) and it's use is discouraged! as he say.
Is there any lib or method to change the theme on runtime?
So far it's impossible and not viable because of themes are immutable.
GreenMatter becomes outdated so regretfully the answer of your question is No way.
More precisely, the color overriding at runtime is not working. There is no fix found at the moment. The future of this feature is uncertain.
I need to edit default AlertDialog theme so that it will look like part of the design of my app. I don't want to create a whole new theme for it. I will just play with its own properties and make small changes. But the problem is I can't manage to reach the source code and I don't know what kind of attributes it has.
What I need to do is basically to give background a little transparency and roundness.
Does anyone know where can I get the AlertDialog style code? And which attributes do I need to edit for transparency and roundness of background?
Thanks.
Here's the style code for AlertDialog: https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
I don't know how to change it the way you want though.
I would like to change the default orange color that appears when someone press an Android button. I have done many searches but all I found was the use of selectors.
I understand the principle, but I don't want to modify the grey aspect of the normal button (not pressed). But using selectors force to define all characteristics of all aspects (pressed or not).
I don't know how to obtain the default aspect of buttons in the light theme, so can anyone tell me where I can find the original parameters of the light theme or at least give me another means to simply change the color of the button when clicked?
You can copy the Android's selector into your project, the one that Android sets it by default to buttons, and modify only the state when the button is pressed by just changing one single drawable.
You could find the file in \android-sdk\platforms\android-10\data\res\drawable\btn_default.xml
Sorry bro...........
i guess only selector will help you......
You must go with selector.....
and selector are reusable xmls you can use in all buttons.....:)
You can refer below link.
:)
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
I tried to find a solution to this problem, but did not succeed.
Maybe this will help:
How to modify the default button state in Android without affecting the pressed and selected states?
Standard Android Button with a different color
So I'm setting a button's background doing this:
b.setBackgroundResource(R.drawable.custom_button1);
How do I programmatically set it back to the default (boring grey) Android button? Is there a R.android.boring_grey resource identifier I can reference without recreating those states myself? Couldn't seem to find it. Maybe my Googling skills are failing me.
Oh and by the way I tried this:
b.setBackgroundResource(0);
And the button actually disappeared (blended with black background?).
Have you tried this?
android.R.drawable.btn_default;
first get the default background of Button b; using
Drawable d = b.getBackground();
then set another background of your choice
b.setBackgroundResource(R.drawable.custom_button1);
if you need default background again use this
b.setBackgroundDrawable(d);
Use this
b.tr.setBackgroundDrawable(null);
I did it by
this.setBackgroundResource(android.R.drawable.btn_default);
try
button.setBackgroundResourses(R.drawable.yourimage);
it will set the default background of buttons.
and you can read more default properties of android widgets from given link:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
Drawable for "modern" button in XML is #android:drawable/btn_default_material
It does not exist in android.R.drawable for some reason.
EDIT: it's private, so don't use it.
I have a TextView which I dynamically add clickable links via Linkify (with a custom TransformFilter). This all works great. What I would like to do now is change the background color of the link when its clicked. In CSS it would be done via the :active pseudo-selector.
I would think I can specify this in styles.xml but I dont know what the parameter name is.
Just had this problem myself and the solution for me (but I didn't use Linkify) was the android:textColorHighlight attribute. I used android:linksClickable="true" instead of Linkify though. That won't probably make any difference.
This might solve your problem .
Basically you have to define a ColorStateList (a xml to be used as a drawable). For your TextView