A have an Activity (minSDK for my app = 14) to which the #android:style/Theme.Holo.Dialog Theme is applied. I need to set an icon, so I used
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
this.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.share);
I guess the icon is set (because the title moved to the right) but for some reason it is not visible as if it was transparent:
I can't find any logical explanation for this behavior. Any ideas?
P.S. no, my drawable is not the same color as the window's background
If I'm not mistaken then you have to set your icon resource on custom Dialog after calling show on it.
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.share);
Its still a mystery why does it work and not the other way :)
it is order:
1 ) this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
2) this.setContentView(R.layout.xxx);
if is Dialog (dialog.show();)
3) this.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.share);
Related
I have a seekbar and i am trying to change the thumb color. I found two photos that describes what i actually want to do.
I have this seekbar (default) :
and i am trying to change it's color thumb like this.. :
(I know how to change background progress color but not the thumb color)..
seekBar1calling.getProgressDrawable().setColorFilter(Color.WHITE, Mode.SRC_IN);
Is there any way to achieve this using java code? Thanks in advance!!
I just used an online style generator which gave me what i needed
http://android-holo-colors.com/
Just choose the widget and color you want and you are ready! ;)
Just use:
mySeekbar.getThumb().setColorFilter(myColor, PorterDuff.Mode.MULTIPLY);
Edit: method getThumb is only available since API 16+ (Jelly Bean).
The other answers are old and didn't work for me, this did.
seekbar.setThumbTintList(ContextCompat.getColorStateList(this, R.color.disabled));
Here is a quick and easy solution which worked for me as expected. Just implement this code after you initialized the seekbar to avoid NPE's.
You have to define the color itself under res/values/colors.xml
int blue = ContextCompat.getColor(context, R.color.seekbar_blue);
filterSeekBar.getThumb().setColorFilter(blue, PorterDuff.Mode.SRC_ATOP);
filterSeekBar.getProgressDrawable().setColorFilter(blue, PorterDuff.Mode.SRC_ATOP);
That's all!
Note: The color of the Progress-Background is not as dark as the Button / Thumb itself.
If you want to know more about the PorfuerDuff part check this answer on Stackoverflow:
Phasmal & Lee's answer to PorfuerDuff modes
how to use color state list for background?
I know android:background="#drawable/drawable_selector", but android:background="#color/color_selector" will cause exceptions.
but android:background="#FFFFFF" works again, can anyone explains why?
now i want to change a layout's background color(not a drawable) when it's pressed,
how to do it?
dynamically you can change like this. Use this if it is useful for you -
textView.setBackgroundColor(Color.parseColor(getResources().getString(R.string.red)));
put the color in res/values/colors.xml,
like #FFFFFF,
and then create a drawable xml in drawable directory,
,that is ok.
I want to set a setError method to my EditText, with a custom icon instead of the default Android icon. So I tried this:
((EditText)findViewById(R.id.edtTitle)).setError(getResources().getText(R.string.errEmptyTitle),
getResources().getDrawable(R.drawable.ico_warning_small);
It shows me the custom message, but not the custom icon. I tried this as well:
Drawable warning = (Drawable)getResources().getDrawable(R.drawable.ico_warning_small);
((EditText)findViewById(R.id.edtTitle))
.setError(getResources().getText(R.string.errEmptyTitle), warning);
Pretty much the same, but I still decided to give it a go. However this also didn't help - I still can't see the icon.
I tried to use some other Android system icon, just to see if I see them and no, I don't see them as well.
So what am I doing wrong? Is there any way to set that custom icon?
You need to set the bounds on the drawable before using it in setError.
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
editText.setError("error", drawable);
If you don't want to show any icon at all, use
editText.setError("error", null);
This issue is discussed and resolved here:
EditText setError() with icon but without Popup message
I hope that by extending the answer it would not get auto-converted to a comment.
Drawable customErrorDrawable = getResources().getDrawable(R.drawable.error_icon);
customErrorDrawable.setBounds(0, 0, customErrorDrawable.getIntrinsicWidth(), customErrorDrawable.getIntrinsicHeight());
editText.setError("please enter data",customErrorDrawable);
Is there a way to totally remove the Icon from a RadioButton?
I'm bolding the text instead of using the icon.
Setting android:button to either #null or #android:color/transparent
only hides the button and still messes up my test positioning.
I suppose that I could use a dummy view that's only 1dip big, but I wanted to check if there was less of a hack.
Try setting the background and button to #null.
set android:button="#null" will remove the default radio icon
Can we change the colour of title in an Android application.
I want to change the colour of label which has contents Abc Supply Company.
This label is in Manifest file. Can we change the colour for this label.
Looking forward to your reply.
thanks.
I think you want to change color of Application Label that comes in every screen.If i am right then there is no solution
In this case you have use theme for activity in android manifest file like this to remove that label
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
Then design you own custom Label in Layout and then you can do whatever you want to do.
Hope this help you :)
Solution for this is known as Custom Title bar in Android, check this article: http://coderzheaven.com/2011/06/custom-title-bar-in-android/
Of course you can do.
You need to get reference of your
Textview yourTextView = ( TextView ) findViewById( R.id.YOUR_TEXT_VIEW );
and then call the function setTextColor( YOUR COLOR );