Reputation: 15
In my application Im creating 10 checkboxes during runtime and I want to set the following xml attributes programmatically. I've been searching everywhere and cannot find any solution and I'm pretty new to android development. Would appreciate any kind of help!
android:button="@null"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
I've been researching on how to access the android:attr file without any success.
Upvotes: 1
Views: 617
Reputation: 363737
You can use the setButtonDrawable
to assign android:button="@null"
CheckBox checkBox = findViewById(R.id.checkbox);
checkBox.setButtonDrawable(null);
You can the setCompoundDrawablesRelativeWithIntrinsicBounds()
method to assign the drawable. Use this code to get the value of ?android:attr/listChoiceIndicatorMultiple
:
TypedValue typeValue = new TypedValue();
getTheme().resolveAttribute(android.R.attr.listChoiceIndicatorMultiple,typeValue, true);
checkBox.setCompoundDrawablesRelativeWithIntrinsicBounds(0,typeValue.resourceId,0,0);
Upvotes: 2
Reputation: 256
button.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
for drawable
setButtonDrawable(Drawable d)
for button
Upvotes: 0