Is there any way to disable a view without leaving it gray?

0

I'd like to standardize views, some screens to view and edit, and others to view. In view mode I leave the views disabled.

I'm trying to keep looking similar by using the following code:

private void enableControls(boolean enable, ViewGroup vg){
    for (int i = 0; i < vg.getChildCount(); i++){
        View child = vg.getChildAt(i);
        child.setEnabled(enable);
        if(enable)
            child.setAlpha(1);
        else
            child.setAlpha(.9f);

        if (child instanceof ViewGroup){
            enableControls(enable, (ViewGroup) child);
        }
    }
}
    
asked by anonymous 07.03.2016 / 14:33

1 answer

1

Hello, Create a custom xml for this view and change the color there when it is disabled and then call on background="@drawable/seu_xml

Create an xml in the drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/disable" />
    <item android:color="@color/enable"/>
</selector>
    
07.03.2016 / 14:46