CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2018-07-29
by Mikhael Lauda

Original Post

Original - Posted on 2010-09-18
by Konstantin Burov



            
Present in both answers; Present only in the new answer; Present only in the old answer;

**Here is my code, to make different colors on button, and Linear, Constraint and Scroll Layout**
First, you need to make a custom_button.xml on your drawable
1. Go to res 2. Expand it, right click on drawable 3. New -> Drawable Resource File 4. File Name : custom_button, Click OK
**Custom_Button.xml Code**
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/red"/> <!-- pressed --> <item android:state_focused="true" android:drawable="@color/blue"/> <!-- focused --> <item android:drawable="@color/black"/> <!-- default --> </selector>
Second, go to res
1. Expand values 2. Double click on colors.xml 3. Copy the code below
**Colors.xml Code**
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color>
<color name="black">#000</color> <color name="violet">#9400D3</color> <color name="indigo">#4B0082</color> <color name="blue">#0000FF</color> <color name="green">#00FF00</color> <color name="yellow">#FFFF00</color> <color name="orange">#FF7F00</color> <color name="red">#FF0000</color> </resources>
**Screenshots below**
[![enter image description here][1]][1] XML Coding [![enter image description here][2]][2] Design Preview
[1]: https://i.stack.imgur.com/PpabI.png [2]: https://i.stack.imgur.com/HkCQF.png
As your error states, you have to define *drawable* attibute for the items (for some reason it is required when it comes to background definitions), so:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/red"/> <!-- pressed --> <item android:state_focused="true" android:drawable="@color/blue"/> <!-- focused --> <item android:drawable="@color/black"/> <!-- default --> </selector>
Also note that *drawable* attribute doesn't accept raw color values, so you have to define the colors as resources. Create *colors.xml* file at *res/values* folder:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="black">#000</color> <color name="blue">#00f</color> <color name="red">#f00</color> </resources>


        
Present in both answers; Present only in the new answer; Present only in the old answer;