How can we custmize Check Box in Android? - 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....

Related

Extended Android Floating Button

I developed Android Application and I want to use extended floating button like floating button on Path Application in my layout. I hope someone can give me example about the code how to make this things. Thank You.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hellooooo"
app:icon = "#drawable/pass_resource_here"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
</com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton>
Here's a detailed tutorial on how to create a good extended floating button with animations https://www.learn2crack.com/2015/10/android-floating-action-button-animations.html
Try using this library and modify it to your liking by using the sam ple project in the library
https://github.com/oguzbilgener/CircularFloatingActionMenu

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

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"

Is it possible to make a checkbox/radio button uncheckable?

The program I am making has several views in which the user is trying to basically figure out a lot of boolean values. Sounds strange, but what I mean is that my device will connect to another device via bluetooth, and then read the status of that device. I basically display a checklist of the current status of that device. So depending on what that device is doing, different checkboxes are checked. Is there a way to make all of the checkboxes unselectable?
Even better, is there a way to hardcode this into the XML file?
Have you considered using android:clickable for an xml attribute for your checkboxes?
From the documentation:
Defines whether this view reacts to click events.
If it cannot react to click events, then it effectively becomes uncheckable.
<CheckBox
android:id="#+id/blahblah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false" />
and in your code you can call cbox.setChecked(boolean)
to expand on what crocboy and nicholas.hauschild said.
Setting this in you XML
android:enabled="false"
will make the button/checkbox be grayed-out, to show it is disabled
Another way to do this is to set it to:
android:clickable="false"
Here is the code to make a RadioButton that is red, that turns green when checked (in your code), but can not be checked by the user.
android:checked="false"
android:textColor="#d1d2d4"
android:buttonTint="#d1202d"
android:textColorHighlight="#248d51"
android:clickable="false"
AND here is the code to check it (this is using JSON: so it is checking if english=="yes")
String yes = "yes";
if(yourObject.english.equals(yes)) {
if (m_english.isChecked()) {/*do nothing */}
else m_english.toggle();
}
Check this out: http://developer.android.com/reference/android/widget/CheckBox.html
You can use checkbox.setEnabled(false) to make it unselectable.
Try this in your XML: android:enabled="false"
It's supposedly deprecated, but may work depending on your traget SDK.
Hope that helps!

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.

Button with image without the regular button shape: Android

I have an image which I want to use as a button. But I want only the image to be visible as the button, with the shape of the image (I do not want the regular button around the image, nor I want the regular button shape). How can I achieve this? Can I achieve this without designing a custom button?
Check the android developers reference and Tutorial Custom Button. It's exactly what you need!
Set the image with button.setBackgroundDrawable (or Resource, etc.)
Use ImageButton with background property set to some color i.e. #000 and no padding
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" android:background="#drawable/ic_launcher"/>

Categories

Resources