按钮样式
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 颜色-->
<solid
android:color="#FF9900"/>
<!-- 圆角-->
<corners
android:radius="5dp"/>
</shape>
solid 实体
stroke 边框
按钮按压样式
<!--按压时-->
<item android:state_pressed="true">
<shape>
<solid android:color="#CC7A00" />
<corners android:radius="10dp" />
</shape>
</item>
<!--非按压时-->
<item android:state_pressed="false">
<shape>
<solid android:color="#FF9900" />
<corners android:radius="10dp" />
</shape>
</item>
在button中添加点击事件
在button中添加属性
android:onClick=”showToast”
之后在对应的java文件中对showToast进行声明
public void showToast(View view){
Toast.makeText(this,"我被点击了",Toast.LENGTH_SHORT).show();
}
另一种设置点击事件的方法
private Button mbtnbutton,mbtnbutton3;
mbtnbutton3 = findViewById(R.id.btn_3);
mbtnbutton3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,edittext.class);
startActivity(intent);
}
});
gravity 内容的对齐方式
原创文章,作者:wdmbts,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/272297.html