Instantly share code, notes, and snippets.
Created
June 7, 2019 03:32
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save NarFooZ/622ecdd56103636c8c7a5db11e3b4e7e to your computer and use it in GitHub Desktop.
learn android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blue button | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#449def" /> | |
<stroke | |
android:width="1dp" | |
android:color="#2f6699" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#449def" | |
android:endColor="#2f6699" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#2f6699" /> | |
<corners | |
android:radius="4dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
Red button | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#ef4444" /> | |
<stroke | |
android:width="1dp" | |
android:color="#992f2f" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#ef4444" | |
android:endColor="#992f2f" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#992f2f" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
Purple button | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#a276eb" /> | |
<stroke | |
android:width="1dp" | |
android:color="#6a3ab2" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#a276eb" | |
android:endColor="#6a3ab2" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#6a3ab2" /> | |
<corners | |
android:radius="4dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
Green button | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#70c656" /> | |
<stroke | |
android:width="1dp" | |
android:color="#53933f" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#70c656" | |
android:endColor="#53933f" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#53933f" /> | |
<corners | |
android:radius="4dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
Yellowbutton | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#f3ae1b" /> | |
<stroke | |
android:width="1dp" | |
android:color="#bb6008" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#f3ae1b" | |
android:endColor="#bb6008" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#bb6008" /> | |
<corners | |
android:radius="4dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
Blackbutton | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" > | |
<shape> | |
<solid | |
android:color="#343434" /> | |
<stroke | |
android:width="1dp" | |
android:color="#171717" /> | |
<corners | |
android:radius="3dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
<item> | |
<shape> | |
<gradient | |
android:startColor="#343434" | |
android:endColor="#171717" | |
android:angle="270" /> | |
<stroke | |
android:width="1dp" | |
android:color="#171717" /> | |
<corners | |
android:radius="4dp" /> | |
<padding | |
android:left="10dp" | |
android:top="10dp" | |
android:right="10dp" | |
android:bottom="10dp" /> | |
</shape> | |
</item> | |
</selector> | |
All text on the buttons will have the same styleso we can define a style in strings.xml: | |
<style name="ButtonText"> | |
<item name="android:layout_width">fill_parent</item> | |
<item name="android:layout_height">wrap_content</item> | |
<item name="android:textColor">#ffffff</item> | |
<item name="android:gravity">center</item> | |
<item name="android:layout_margin">3dp</item> | |
<item name="android:textSize">30dp</item> | |
<item name="android:textStyle">bold</item> | |
<item name="android:shadowColor">#000000</item> | |
<item name="android:shadowDx">1</item> | |
<item name="android:shadowDy">1</item> | |
<item name="android:shadowRadius">2</item> | |
</style> | |
Together you’ll have a nice collection of nice buttons: | |
Source code of an activity layout: | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" | |
android:orientation="vertical"> | |
<Button android:text="Button" android:id="@+id/button1" android:background="@drawable/btn_red" style="@style/ButtonText"></Button> | |
<Button android:text="Button" android:id="@+id/button2" android:background="@drawable/btn_blue" style="@style/ButtonText"></Button> | |
<Button android:text="Button" android:id="@+id/button3" android:background="@drawable/btn_purple" style="@style/ButtonText"></Button> | |
<Button android:text="Button" android:id="@+id/button4" android:background="@drawable/btn_green" style="@style/ButtonText"></Button> | |
<Button android:text="Button" android:id="@+id/button5" android:background="@drawable/btn_orange" style="@style/ButtonText"></Button> | |
<Button android:text="Button" android:id="@+id/button6" android:background="@drawable/btn_black" style="@style/ButtonText"></Button> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment