How to remove the button image of checkbox by java coding? - android

I know to remove the button image of checkbox in xml with following code:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="25dp"
android:button="#null"
android:background="#drawable/notxtcheckboxbtn"
android:layout_weight="1"/>
But I need to add checkbox in my java code. And "newCheckBox.setButtonDrawable(null);" doesn't work!
Anybody know how to remove it in java code? Thanks in advance!!!

In the case that you just want the image to be transparent, you could try setting the image to android.R.color.transparent. That should get you the effect you're looking for.
Otherwise if you want to hide the button and disable it, you can use set visibility() and set it to gone or invisible.

Try:
android:button="#android:color/transparent"

Related

DrawableStart is messing with me

I want to add an image to the left of the text in the button. So I used the below piece of code
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:drawableLeft="#drawable/ic_login"
/>
After doing this, the Layout Editor shows me this
But since there's no android:drawableStart Android Studio complains to me about this and when I add it. The final code looks like this:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:drawableLeft="#drawable/ic_login"
android:drawableStart="#drawable/ic_login"/>
and now the button looks like this -_-
I know, one solution could be to just ignore the warning but I don't think that's what's recommended.
P.S. If I just do drawableStart then also no image is shown.
What should I do, am I missing something crucial?
You can just get rid of the warning in this case by doing (Windows) alt+enter and then ignore it for that specific view
That will add a attribute so you'll still know it's ignored on purpose when looking at the view.
I think it just need to set layout direction :
android:layoutDirection="ltr"
it will be automaticlly replace

Android button elevation shadow not working

I am trying to make a button that has a shadow using elevation with a background image being my sign in with gmail png. The button is contained within a relative layout. The elevation won't show no matter what I try to do. I tried solutions from other forum questions and none worked.
Here is my code for the button
<Button
android:id="#+id/google"
android:layout_width="270dp"
android:layout_height="38dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:background="#drawable/google"
android:elevation="10dp"
android:layout_below="#id/slogan"/>
The google drawable is a png image that I exported from Adobe XD.
Could someone please give me a pointer on what I am doing wrong? Thanks.
Additionally, I realize that if I set the background of the button to android:color/white the shadow appears. So I think the issue is with the png drawable? Does elevation not work with png images? Is there a workaround?
Use below the line of code to show an elevation in button
android:outlineProvider="bounds" – K. Sopheak
That works, thanks!
try this I hope it helps, because another view or layout just after your button is hiding shadow
android:layout_marginBottom="16dp"
For Material Button, I tried the following and it worked
android:translationZ="5dp"
Since you're using an image, replace the <Button> tag with that of an <ImageButton>. So, your workaround code would be:
<ImageButton
android:id="#+id/google"
android:layout_width="270dp"
android:layout_height="38dp"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:src="#drawable/google"
android:elevation="10dp"
android:layout_below="#id/slogan"/>
Take note that the android:src attribute is being used here rather than the android:background attribute.
This one worked for me!
try this , I hope this help you ||
android:layout_margin="5dp"

How to add image buttons with ripple effect in cardview?

I'm looking at implementing a cardview which has a button with the ripple effect.
I'm talking about something like this :
https://lh5.ggpht.com/uTRdkJMNyy3KasauJsyGTTRHn5EZBtmA3-BVHCaHWiqBIF_XQmJg_MuE8OdisvefdEk=h900-rw)
I'm trying to implement the download/share button as present on those cards.
Should I be using an ImageButton or something else?
Also, how can I extend the same support for pre-lollipop devices?
UPDATE:
This is the code I'm using right now. It gives me an image button but I'n not able to get touch/ripple effects. The android:foreground property works for cardView and gives the ripple effect, but not for ImageButton.
<ImageButton
android:id="#+id/ib_open_map"
android:background="#drawable/ic_directions_grey600_36dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
I think this can be interesting for you.
You will have to import or link the library to be able to use it.
Here is the link to the library :
Link to the library
It is easy to use and it is based on imageView.
Hope it helps you :) Let me know
EDIT
Editing my link for your update :)
Take a look at this : MaterialRipple

How to make a checkbox look better in android

This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.

How can we custmize Check Box in Android?

I want to display Check box like Radio button though is it possible to give our own shape to the check box
if possible than help me please thanks
Yes. It is possible. Use this code
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#android:drawable/btn_radio"/>
you need to set your own shape or image for both of it's state and have to handle it in the code....

Categories

Resources