自学安卓笔记2(button)

xiaoxiao2021-02-28  56

button是TextView的子类,首先复习上节课的内容

          布局文件中弄好button中后 在Java文件中

 1.首先声明控件 private Button mBtnButton;

2.然后找到控件,设置点击监听跳转界面

mBtnButton = findViewById(R.id.btn_button); mBtnButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //跳转到Button演示界面 Intent intent = new Intent(MainActivity. this,ButtonActivity. class);//跳转到 startActivity(intent); }})        1.自定义button的背景形状          1.1圆角矩形                     在drawabe中new一个drawable resources file                                 起个名字,填好root element(这里我们使用shape) <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ff9900" /> <corners android:radius="20dp"/> //还有许多其他属性自行百度 </shape>

    2.自定义button的按压效果      3.点击事件

1.1

转载请注明原文地址: https://www.6miu.com/read-2631718.html

最新回复(0)