返回系统HOME桌面
2016-01-09 20:34
387 查看
1、布局文件
2、MainActivity类
<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 } }); } }
相关文章推荐
- 含义while((ch=getchar())!='#'){},while(ch=getchar(),ch!='#'),while(ch=getchar() && ch!='#')
- 在 NetBeans IDE 中调试 PHP 源代码
- 转: Oracle AWR 报告 每天自动生成并发送邮箱
- 重拾拓展欧几里得 & 简单不定方程
- 说完电调就是螺旋桨了
- #Objective - C - UI-design - 第四天 -UIKit框架-UIKit-事件手势-刮刮乐小游戏
- Python修改当前工作目录
- Android 开发中百度地图运行一段时间地图轨迹不更新的问题
- 人见人爱A+B(1)
- iOS navigation (pop)返回按钮点击提示框
- 快播CEO王欣受审:贾跃亭微博受网友围攻声讨
- Git(二)基本操作
- 开通博客的第一帖
- MongoDB:如何正常关闭服务(转)
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState解决?
- SMO推导和代码-记录毕业论文4
- linux下搭建nagios监控
- 周易六十四卦——地天泰卦
- java表 ADT
- uva 10340 子序列