Working with Buttons in Android Studio
From the previous article we went through a basic introduction on Android Studio.This article help you to get to know about Buttons in android studio.Open up Android studio and start.
Given below is the edited code of the text view that I have used.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello World!"
android:textSize="36sp"
android:id="@+id/textView" />
Go to your palette in the project. Then drag and place the button where you need in the content.
There is an ID given to the button to identify a particular component which is always unique. You can give name to the button in android.text. Now give a background color to the button.
Method 1 : Using inbuilt colors
android:background="@android:color/darker_gray"
By typing android:background="@android:color you can get colors that are there in the collection.
Method 2 : Define the Color
android:background="@color/colorAccent"
android:background="@color/colorPrimary"
android:background="@color/colorPrimaryDark"
You can define your own color by moving on to app>src>main>res>values>colors.xml.
<color name="colormycolor">#8184A0</color> <color name="colormycolor1">#E8A08E</color> <color name="colormycolor2">#D1E0AF</color>
Above are the set of colors that I have defined.Now move onto activity_main.xml and try out.
Similarly you can change the color of the text in the button.
android:textColor="@android:color/black"
Comments
Post a Comment