您的位置:首页 > 其它

返回系统HOME桌面

2016-01-09 20:34 387 查看
1、布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/home_button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回HOME"
android:textColor="@android:color/black"/>

</LinearLayout>


2、MainActivity类

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button home = (Button)findViewById(R.id.home_button1);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);//设置Intent动作
intent.addCategory(Intent.CATEGORY_HOME);//设置Intent种类
startActivity(intent);//将Intent传递给Activity
}
});
}
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: