Setting @null for textColor dynamically in android

1.7k Views Asked by At

I need an EditText to appear as a TextView for a form that will change from being write to read only. I have found a useful snippet of code to do this in a layout:

<EditText android:id="@+id/title"
          android:layout_width="fill_parent"
          style="?android:attr/textViewStyle"
          android:background="@null"
          android:textColor="@null" /> 

I need to do this dynamically (not in the layout). I know that the background can be set to @null by using setBackgroundResource(null). Because setTextColor(int color) takes an int, I assume that a specific color must be selected. What is the correct color to choose that would be the equivalent to @null? A color from the default theme? Or is there a better way to do this?

2

There are 2 best solutions below

3
On

You can call these methods on any View to disable editing or clicking. It will effectively make the view read only. Set them to true to re-enable them.

view.setFocusable(false);
view.setClickable(false);
view.setLongClickable(false);
3
On

You can create color in your string.xml like

<color name="transparent">#00000000</color>   

Then you can assign it to like

txtTitle.setTextColor(getResources().getColor(R.color.transparent));    

#00000000 is equal to null.