First Type: Code
Setting_view.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "55DP" >
<textview
Android:id= "@+id/tv_title"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Attribution to display Settings"
Android:textsize= "20sp"/>
<textview
Android:id= "@+id/tv_content"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@id/tv_title"
Android:text= "The place of attribution has been opened"
Android:textsize= "16sp"/>
<checkbox
Android:id= "@+id/cb_status"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentright= "true"
Android:layout_centerinparent= "true"
Android:checked= "true"/>
</RelativeLayout>
public class Mainactivity extends Activity {
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Settingview SV = new Settingview (this);
Setcontentview (SV); }
}
public class Settingview extends Relativelayout {
Public Settingview (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
Initui (context); }
Public Settingview (context context, AttributeSet Attrs) {
Super (context, attrs);
Initui (context); }
Public Settingview (Context context) {
Super (context);
Initui (context); }
private void Initui (context context) {
View view = view.inflate (context, r.layout.setting_view, null);
This.addview (view);//this refers to the object that invokes the AddView (view) method, which is the parameter context}
}
Second way: XML format
Two ways to customize a control