I'm setting android:enabled="false"
on a custom view, but it doesn't appear to be having any effect on the isEnabled()
property.
Here's a simple test case:
public class TestView extends View {
public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint();
p.setTextAlign(Align.CENTER);
p.setTextSize(ViewUtils.dpToPx(this, 10));
canvas.drawText("Enabled = " + (isEnabled() ? "true" : "false"),
getWidth() / 2,
getHeight() / 2,
p);
}
}
And the corresponding XML:
<com.example.TestView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/darker_gray"
android:enabled="false"
android:layout_width="100dp"
android:layout_height="100dp"/>
The output view looks like this:
Can someone please explain why?
Use this instead:
app:enabled="@{false}"
As far as I can tell, android:enabled
is not an attribute of View
, as it is not in the documentation.
I don't think there is a way to modify the return value of isEnabled()
via the XML layout file. (Unless defining custom attributes for a custom view)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With