Android定义按钮返回上一个页面(Activity)
直接 finish(); 关闭当前Activity即可,
public class InDevelopments extends AppCompatActivity {
// ↓ 定义textview,你是什么就定义什么,比如button就定义button从上面引入相应类
private TextView findDevices; //重点
protected void onCreate(Bundle savedInstanceState) {
// ↓ 不解释
super.onCreate(savedInstanceState);
setContentView(R.layout.components_development);
// ↓ 重点
findDevices = (TextView) findViewById(R.id.back);
// 绑定点击事件
findDevices.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
finish(); //直接关闭当前页面
}
});
}
}
按钮部分的布局:
<TextView
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="返回"
android:gravity="center"
android:textSize="18sp"
android:textColor="#3F51B5"
android:layout_marginTop="10dp" />
下方的返回按键。