Android - Button component of basic control Button (5)

1.Knowledge points

(1) Master the definition format of the button component class;

(2) Buttons can be defined in Activity;

2.Specific content

 

It was discovered that Button is actually a special text display component . It means that the properties or methods used on the text display component can be used on the Button.

<Button 
        android:id="@+id/mybut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       	android:text="你点我呀"
       	android:textSize="25px"
       	android:textStyle="italic"—设置斜体
        />
<Button 
        android:id="@+id/mybut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       	android:text="你点我呀"
       	android:textSize="25px"
       	android:textStyle="italic"
        />
    <Button 
        android:id="@+id/mybut1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       	android:text="打工人最美"
        />
     <Button 
        android:id="@+id/mybut2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       	android:text="https://blog.csdn.net/weixin_41830242?type=blog"
        />

 The above all define buttons in the layout file. Of course, we can also use the Activity program to define buttons:

public class ButtonActivity extends Activity {
	private LinearLayout mylayout = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);
        this.mylayout = (LinearLayout) super.findViewById(R.id.mylayout);
        Button but = new Button(this);//在Activity程序中实例化新的组件的时候都需要传入参数:Context对象--Android上下文对象
        but.setText("毛栗子");//设置显示内容
        this.mylayout.addView(but);//将Button组件放入到布局管理器中
    } 
}

 3. Summary

     Button is a subclass of TextView and is a special text. 

Guess you like

Origin blog.csdn.net/weixin_41830242/article/details/131181363