Android Ui
Android Ui
code in XML:
<TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid" />
Attributes of TextView:
Now let’s we discuss about the attributes that helps us to configure a TextView in
your xml file.
1. id: id is an attribute used to uniquely identify a text view. Below is the example code
in which we set the id of a text view.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
2. gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc.
Below is the example code with explanation included in which we set the
center_horizontal gravity for text of a TextView.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:textSize="20sp"
android:gravity="center_horizontal"/> <!--center horizontal gravity-->
3. text: text attribute is used to set the text in a text view. We can set the text in xml as
well as in the java class.
Below is the example code with explanation included in which we set the text
“AbhiAndroid” in a text view.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:text="AbhiAndroid"/><!--Display Text as AbhiAndroid-->
In Java class:
Below is the example code in which we set the text in a textview programmatically
means in java class.
4. textColor: textColor attribute is used to set the text color of a text view. Color value is
in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below is the example code with explanation included in which we set the red color for
the displayed text.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#f00"/><!--red color for text view-->
In Java class:
Below is the example code in which we set the text color of a text view
programmatically means in java class.
TextView textView = (TextView)findViewById(R.id.textView);
textView.setTextColor(Color.RED); //set red color for text view
5. textSize: textSize attribute is used to set the size of text of a text view. We can set the
text size in sp(scale independent pixel) or dp(density pixel).
Below is the example code in which we set the 20sp size for the text of a text view.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="40sp" /><!--Set size-->
In Java class:
Below is the example code in which we set the text size of a text view programmatically
means in java class.
6. textStyle: textStyle attribute is used to set the text style of a text view. The possible
text styles are bold, italic and normal. If we need to use two or more styles for a text
view then “|” operator is used for that.
Below is the example code with explanation included in which we set the bold and italic
text styles for text.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="40sp"
android:textStyle="bold|italic"/><!--bold and italic text style of text-->
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AbhiAndroid"
android:layout_centerInParent="true"
android:textSize="40sp"
android:padding="10dp"
android:textColor="#fff"
android:background="#000"/> <!--red color for background of text view-->
In Java class:
Below is the example code in which we set the background color of a text view
programmatically means in java class.
EditText
Important Note: An EditText is simply a thin extension of a TextView. An EditText
inherits all the properties of a TextView.
EditText Code:
We can create a EditText instance by declaring it inside a layout(XML file) or by
instantiating it programmatically (i.e. in Java Class).
EditText code in XML:
<EditText
android:id="@+id/simpleEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
Attributes of EditText:
Now let’s we discuss few attributes that helps us to configure a EditText in your xml.
1. id: id is an attribute used to uniquely identify a text EditText. Below is the example
code in which we set the id of a edit text.
<EditText
android:id="@+id/simpleEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
2. gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc.
Below is the example code with explanation included in which we set the right gravity
for text of a EditText.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Email"
android:gravity="right"/><!--gravity of a edit text-->
3. text: text attribute is used to set the text in a EditText. We can set the text in xml as
well as in the java class.
Below is the example code in which we set the text “Username” in a edit text.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Username"/><!--set text in edit text-->
Setting text in EditText In Java class:
Below is the example code in which we set the text in a text view programmatically
means in java class.
4. hint: hint is an attribute used to set the hint i.e. what you want user to enter in
this edit text. Whenever user start to type in edit text the hint will automatically
disappear.
Below is the example code with explanation in which we set the hint of a edit text.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Enter Your Name Here" /><!--display the hint-->
Setting hint in EditText In Java class:
Below is the example code in which we set the text in a text view programmatically
means in java class.
5. textColor: textColor attribute is used to set the text color of a text edit text. Color
value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below is the example code with explanation included in which we set the red color for
the displayed text of a edit text.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Password"
android:textColor="#f00"/><!--set the red text color-->
EditText simpleEditText=(EditText)findViewById(R.id.simpleEditText);
simpleEditText.setTextColor(Color.RED);//set the red text color
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Enter Your Name Here"
android:textColorHint="#0f0"/><!--set the hint color green-->
EditText simpleEditText=(EditText)findViewById(R.id.simpleEditText);
simpleEditText.setHintTextColor(Color.green(0));//set the green hint color
7. textSize: textSize attribute is used to set the size of text of a edit text. We can set the
text size in sp(scale independent pixel) or dp(density pixel).
Below is the example code in which we set the 25sp size for the text of a edit text.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="AbhiAndroid"
android:textSize="25sp" /><!--set 25sp text size-->
EditText simpleEditText=(EditText)findViewById(R.id.simpleEditText);
simpleEditText.setTextSize(25);//set size of text
8. textStyle: textStyle attribute is used to set the text style of a edit text. The possible
text styles are bold, italic and normal. If we need to use two or more styles for a edit
text then “|” operator is used for that.
Below is the example code with explanation included, in which we set the bold and italic
text styles for text.
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Email"
android:textSize="25sp"
android:textStyle="bold|italic"/><!--set bold and italic text style-->
<EditText
android:id="@+id/simpleEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Enter Your Name Here"
android:padding="15dp"
android:textColorHint="#fff"
android:textStyle="bold|italic"
android:background="#000"/><!--set background color black-->
EditText simpleEditText=(EditText)findViewById(R.id.simpleEditText);
simpleEditText.setBackgroundColor(Color.BLACK);//set black background color
10. padding: padding attribute is used to set the padding from left, right, top or bottom.
In above example code of background we also set the 10dp padding from all the side’s
of edit text.
Button
Button code in XML:
The below code will create Button and write “Abhi Android” text on it.
<Button
android:id="@+id/simpleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abhi Android"/>
<Button
android:id="@+id/simpleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abhi Android"/>
2. gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc.
Below is the example code with explanation included in which we set the right and
center vertical gravity for text of a Button.
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Abhi Android"
android:layout_centerInParent="true"
android:gravity="right|center_vertical"/><!--set the gravity of button-->
3. text: text attribute is used to set the text in a Button. We can set the text in xml as
well as in the java class.
Below is the example code with explanation included in which we set the text “Learning
Android @ AbhiAndroid” in a Button.
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Learn Android @ AbhiAndroid"/><!--display text on button-->
4.textColor: textColor attribute is used to set the text color of a Button. Color value is in
the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below is the example code with explanation included in which we set the red color for
the displayed text of a Button.
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="AbhiAndroid"
android:textColor="#f00"/><!--red color for the text-->
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="AbhiAndroid"
android:textSize="25sp" /><!--25sp text size-->
Button simpleButton=(Button)findViewById(R.id.simpleButton);
simpleButton.setTextSize(25);//set the text size of button
6. textStyle: textStyle attribute is used to set the text style of a Button. The possible text
styles are bold, italic and normal. If we need to use two or more styles for a Button then
“|” operator is used for that.
Below is the example code with explanation included, in which we set the bold and italic
text styles for text of a button.
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="AbhiAndroid"
android:textSize="20sp"
android:textStyle="bold|italic"/><!--bold and italic text style-->
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Download"
android:textSize="20sp"
android:padding="15dp"
android:textStyle="bold|italic"
android:background="#147D03" /><!--Background green color-->
Setting background in Button In Java class:
Below is the example code in which we set the background color of a Button
programmatically means in java class.
Button simpleButton=(Button)findViewById(R.id.simpleButton);
simpleButton.setBackgroundColor(Color.BLACK);//set the black color of button
background
8. padding: padding attribute is used to set the padding from left, right, top or bottom.
In above example code of background we also set the 10dp padding from all the side’s
of button.
9. drawableBottom: drawableBottom is the drawable to be drawn to the below of the
text.
Below is the example code in which we set the icon to the below of the text.
Make sure you have image saved in your drawable folder name ic_launcher.
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#147D03"
android:text="Download Code"
android:textSize="20sp"
android:padding="15dp"
android:textStyle="bold|italic"
android:drawableBottom="@drawable/ic_launcher"/><!--image drawable on button-->
10. drawableTop, drawableRight And drawableLeft: Just like the above attribute we
can draw drawable to the left, right or top of text.
In the Below example we set the icon to the right of the text. In the same way you can
do for other two attribute by your own:
<Button
android:id="@+id/simpleButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#147D03"
android:text="Download Code"
android:textSize="20sp"
android:padding="15dp"
android:textStyle="bold|italic"
android:drawableRight="@drawable/ic_launcher"/><!--image drawable on Right side
of Text on button-->
ImageView
Below is an ImageView code in XML:
Make sure to save lion image in drawable folder
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/lion" />
Attributes of ImageView:
Now let’s we discuss some important attributes that helps us to configure a ImageView
in your xml file.
1. id: id is an attribute used to uniquely identify a image view in android. Below is the
example code in which we set the id of a image view.
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
2. src: src is an attribute used to set a source file or you can say image in your imageview
to make your layout attractive.
Below is the example code in which we set the source of a imageview lion which is
saved in drawable folder.
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/lion" /><!--set the source of an image view-->
In Java:
We can also set the source image at run time programmatically in java class. For that we
use setImageResource() method as shown in below example code.
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/lion"
android:background="#000"/><!--black color in background of a image view-->
In Java:
We can also set the background at run time programmatically in java class. In below
example code we set the black color in the background of a image view.
4. padding: padding attribute is used to set the padding from left, right, top or bottom
of the Imageview.
paddingRight: set the padding from the right side of the image view.
paddingLeft: set the padding from the left side of the image view.
paddingTop: set the padding from the top side of the image view.
paddingBottom: set the padding from the bottom side of the image view.
padding: set the padding from the all side’s of the image view.
Below is the example code of padding attribute in which we set the 30dp padding from
all the side’s of a image view.
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000"
android:src="@drawable/lion"
android:padding="30dp"/><!--set 30dp padding from all the sides-->
5. scaleType: scaleType is an attribute used to control how the image should be re-sized
or moved to match the size of this image view. The value for scale type attribute can be
fit_xy, center_crop, fitStart etc.
Below is the example code of scale type in which we set the scale type of image view to
fit_xy.
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/lion"
android:scaleType="fitXY"/><!--set scale type fit xy-->
Let’s we take an another example of scale type to understand the actual working of
scale type in a image view.
In below example code we set the value for scale type “fitStart” which is used to fit the
image in the start of the image view as shown below:
<ImageView
android:id="@+id/simpleImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/lion"
android:scaleType="fitStart"/><!--set scale type fit start of image view-->
CheckBox
CheckBox code in XML:
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple CheckBox"/>
Important Note: You can check the current state of a check box programmatically by
using isChecked() method. This method returns a Boolean value either true or false, if
a check box is checked then it returns true otherwise it returns false. Below is an
example code in which we checked the current state of a check box.
//initiate a check box
CheckBox simpleCheckBox = (CheckBox) findViewById(R.id.simpleCheckBox);
Attributes of CheckBox:
Now let’s we discuss important attributes that helps us to configure a check box
in XML file (layout).
1.id: id is an attribute used to uniquely identify a check box. Below we set the id of a
image button.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple CheckBox"/>
2. checked: checked is an attribute of check box used to set the current state of a check
box. The value should be true or false where true shows the checked state and false
shows unchecked state of a check box. The default value of checked attribute is false.
We can also set the current state programmatically.
Below is an example code in which we set true value for checked attribute that sets the
current state to checked.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple CheckBox"
android:checked="true"/> <!--set the current state of the check box-->
Setting Current State Of CheckBox In Java Class:
Below we set the current state of CheckBox in java class.
3. gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text in CheckBox like left, right, center, top, bottom, center_vertical,
center_horizontal etc.
Below we set the right and center_vertical gravity for the text of a check box.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Simple CheckBox"
android:checked="true"
android:gravity="right|center_vertical"/> <!-- gravity of the check box-->
4. text: text attribute is used to set the text in a check box. We can set the text in xml as
well as in the java class.
Below is the example code with explanation included in which we set the text “Text
Attribute Of Check Box” for a check box.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Text Attribute Of Check Box"/> <!--displayed text of the check
box-->
5. textColor: textColor attribute is used to set the text color of a check box. Color value
is in form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below we set the red color for the displayed text of a check box.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text is Red Color"
android:textColor="#f00"
android:checked="true"/> <!-- red color for the text of check box-->
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text size Attribute Of Check Box"
android:textColor="#00f"
android:checked="false"
android:textSize="20sp"/><!--set Text Size of text in CheckBox-->
7. textStyle: textStyle attribute is used to set the text style of the text of a check box.
The possible text styles are bold, italic and normal. If we need to use two or more styles
for a text view then “|” operator is used for that.
Below we set the bold and italic text styles for text of a check box.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Style Attribute Of Check Box"
android:textColor="#44f"
android:textSize="20sp"
android:checked="false"
android:textStyle="bold|italic"/>
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text size Attribute Of Check Box"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold|italic"
android:checked="true"
android:background="#000" /><!-- black background for the background of check
box-->
Setting Background in CheckBox In Java class:
Below is the example code in which we set the background color of a check box
programmatically means in java class.
9. padding: padding attribute is used to set the padding from left, right, top or bottom.
paddingRight :set the padding from the right side of the check box.
paddingLeft :set the padding from the left side of the check box.
paddingTop :set the padding from the top side of the check box.
paddingBottom :set the padding from the bottom side of the check box.
Padding :set the padding from the all side’s of the check box.
Below is the example code of padding where we set the 30dp padding from all the side’s
of the check box.
<CheckBox
android:id="@+id/simpleCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Padding Attribute Of Check Box"
android:textColor="#44f"
android:textSize="20sp"
android:textStyle="bold|italic"
android:checked="false"
android:padding="30dp"/> <!--30dp padding from all side’s-->
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/simpleRadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
Checking Current State Of Radio Button:
You can check the current state of a radio button programmatically by using isChecked()
method. This method returns a Boolean value either true or false. if it is checked then
returns true otherwise returns false. Below is an example code with explanation in
which we checked the current state of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
2. checked: checked attribute in radio button is used to set the current state of a radio
button. We can set it either true or false where true shows the checked state and false
shows unchecked state of a radio button. As usual default value of checked attribute is
false. We can also set the current state in JAVA.
Below we set true value for checked attribute which sets the current state to checked of
a Button
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"/> <!-- set the current state of the radio button-->
3. text: text attribute is used to set the text in a radio button. We can set the text both
ways either in XML or in JAVA class.
Below is the example code with explanation included in which we set the text “I am a
radiobutton” of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_centerHorizontal="true"
android:text="I am a radiobutton" /> <!-- displayed text of radio button-->
4. gravity: The gravity attribute is an optional attribute which is used to control the
alignment of text like left, right, center, top, bottom, center_vertical, center_horizontal
etc.
Below is the example code with explanation included in which we set the center gravity
for the text of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="I am a Button"
android:gravity="center"/> <!-- center gravity of the text-->
5. textColor: textColor attribute is used to set the text color of a radio button. Color
value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below we set the red color for the displayed text of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_centerHorizontal="true"
android:text="Male"
android:textColor="#f00" /><!--red color for displayed text-->
6. textSize: textSize attribute is used to set the size of the text of a radio button. We can
set the text size in sp(scale independent pixel) or dp(density pixel).
Below we set the 25sp size for the text of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_centerHorizontal="true"
android:text="AbhiAndroid"
android:textColor="#f00"
android:textSize="25sp"/> <!--setting text size-->
7. textStyle: textStyle attribute is used to set the text style of the text of a radio button.
The possible text styles are bold, italic and normal. If we need to use two or more styles
for a text view then “|” operator is used for that.
Below is the example code with explanation included in which we set the bold and italic
text styles for text of a radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textSize="25sp"
android:layout_centerHorizontal="true"
android:text="Male"
android:textColor="#f00"
android:textStyle="bold|italic"/> <!-- bold and italic text style-->
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textSize="25sp"
android:textStyle="bold|italic"
android:padding="20dp"
android:layout_centerHorizontal="true"
android:text="Male"
android:textColor="#f00"
android:background="#000"/> <!-- black background for radio button-->
simpleRadioButton.setBackgroundColor(Color.BLACK);
9. padding: padding attribute is used to set the padding from left, right, top or bottom.
paddingRight: set the padding from the right side of the radio button.
paddingLeft : set the padding from the left side of the radio button.
paddingTop : set the padding from the top side of the radio button.
paddingBottom: set the padding from the bottom side of the radio button.
Padding: set the padding from the all side’s of the radio button.
Below we set padding attribute of 20dp padding from all the side’s of the radio button.
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textSize="25sp"
android:textStyle="bold|italic"
android:layout_centerHorizontal="true"
android:text="AbhiAndroid"
android:textColor="#f00"
android:padding="40dp"/> <!--40dp padding from all the sides of radio button-->
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textSize="25sp"
android:padding="20dp"
android:layout_centerHorizontal="true"
android:text="AbhiAndroid"
android:textColor="#f00"
android:drawableRight="@drawable/ic_launcher" /> <!-- drawable icon at the right
of radio button-->