تغییردادن رنگ متن پس زمینه Radio Button در اندروید

سه شنبه 24 مرداد 1396

در این مقاله قصد داریم رنگ پس زمینه ی radio button را تغییر دهیم مثلا شاید بعضی وقت ها دربعضی از اپلیکیشن ها نیاز داشته باشید رنگ پس زمینه ی radio Button خودتان را تغییر دهید.

تغییردادن رنگ متن پس زمینه Radio Button در اندروید

ابتدا باید کلاس زیر را اضافه نمایید:

package com.changeradiobuttonbackgroundcolor_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }

}

بعد از آن باید xml مورد نظر را قرار دهید:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.changeradiobuttonbackgroundcolor_android_examples.com.MainActivity" >

 
 <RadioGroup
 android:id="@+id/radiogroup"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 
 >
 
 <RadioButton
 android:id="@+id/radioButton1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Android"
 android:background="#fdd101"
 android:padding="15dp"
 />

 <RadioButton
 android:id="@+id/radioButton2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Blogger"
 android:background="#b9fd01"
 android:padding="15dp" />

 <RadioButton
 android:id="@+id/radioButton3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="PHP"
 android:background="#fd01fa"
 android:padding="15dp" />

 </RadioGroup>
</RelativeLayout>

خروجی به صورت زیر خواهد بود:

برنامه نویسان

نویسنده 3355 مقاله در برنامه نویسان

کاربرانی که از نویسنده این مقاله تشکر کرده اند

تاکنون هیچ کاربری از این پست تشکر نکرده است

در صورتی که در رابطه با این مقاله سوالی دارید، در تاپیک های انجمن مطرح کنید