android 24 设置与桌面相同的action和category
设置与桌面相同的action和category
安卓系统桌面也是一个activity,安卓桌面的action和category是:
<activity
android:name="com.sxt.day04_07_twoaction.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />项目入口acticity <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
给自己的acticity设置的和桌面一样,会弹出窗口选择是启动安卓系统桌面的activity还是我们自己的activity。
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="启动桌面Activity" /> </LinearLayout>
main.java
package com.sxt.day04_07_twoaction; import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener; public class MainActivity extends Activity implements OnClickListener{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListener();
} private void setListener() {
findViewById(R.id.btnHome).setOnClickListener(this);
} @Override
public void onClick(View v) {
Intent intent=new Intent();
switch (v.getId()) {
case R.id.btnHome:
intent.addCategory(Intent.CATEGORY_HOME);
intent.setAction(Intent.ACTION_MAIN);//这里用常量,也可以写字符串
break;
}
startActivity(intent);
}
}
系统描述文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sxt.day04_07_twoaction"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sxt.day04_07_twoaction.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sxt.day04_07_twoaction.SecondActivity" //要启动的activity的java类
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>与桌面activity相同的时候也要加上这个,然后再设置一个category
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</activity>
</application> </manifest>
SecondActivity.java
package com.sxt.day04_07_twoaction; import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu; public class SecondActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second); //加载xml文件
Log.i("main","SecondActivity");
} }
SecondActivity.xml
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SecondActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>
效果:

android 24 设置与桌面相同的action和category的更多相关文章
- android widget 开发实例 : 桌面便签程序的实现具体解释和源代码 (上)
如有错漏请不吝拍砖指正,转载请注明出处,很感谢 桌面便签软件是android上经常使用软件的一种,比方比較早的Sticky Note,就曾很流行, Sticky Note的介绍能够參见 http:// ...
- Android UI开发第二十四篇——Action Bar
Action bar是一个标识应用程序和用户位置的窗口功能,并且给用户提供操作和导航模式.在大多数的情况下,当你需要突出展现用户行为或全局导航的activity中使用action bar,因为acti ...
- 【转】Android UI开发第二十四篇——Action Bar
Action bar是一个标识应用程序和用户位置的窗口功能,并且给用户提供操作和导航模式.在大多数的情况下,当你需要突出展现用户行为或全局导航的activity中使用action bar,因为acti ...
- Android闹钟设置的解决方案
Android设置闹钟并不像IOS那样这么简单,做过Android设置闹钟的开发者都知道里面的坑有多深.下面记录一下,我解决Android闹钟设置的解决方案. 主要问题 API19开始AlarmMan ...
- (转)Android属性设置android:noHistory="true"
设置 android:noHistory="true"后,该Activity在statck中不留历史痕迹.默认的值是false. 举例说明,假设有三个Activity分别是:A,B ...
- Android中设置全屏的方法
在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果.其一,通过在代码中可以设置,其二,通过manifest配置文件来设置全屏. 其 ...
- Android强制设置横屏或竖屏
全屏 在Activity的onCreate方法中的setContentView(myview)调用之前添加下面代码 requestWindowFeature(Window.FEATURE_NO_TIT ...
- 【Android】Mac下Android Studio设置App启动页
先将启动页放到项目资源中,图片一般是1080*1920的jpg. 新建一个activity,如图: 创建成功之后,打开刚刚创建的activity,来进行代码的编写: public class BZLa ...
- 05 Android强制设置横屏或竖屏/全屏
全屏 在Activity的onCreate方法中的setContentView(myview)调用之前添加下面代码 requestWindowFeature(Window.FEATURE_NO_TIT ...
随机推荐
- 2016030203 - 首次将内容推送到github中
参考网址:http://www.cnblogs.com/plinx/archive/2013/04/08/3009159.html 和当你在你的github上创建repository后的提示信息如下 ...
- Struts2技术内幕-----第七章
1)基于人机交互的请求--响应模式主要由哪三大要素构成? ①沟通协议-----人和机器都能够明白的数据通信格式 ②请求内容-----人通过某种机制向机器发起的数据请求 ③响应内 ...
- 全连接的BP神经网络
<全连接的BP神经网络> 本文主要描述全连接的BP神经网络的前向传播和误差反向传播,所有的符号都用Ng的Machine learning的习惯.下图给出了某个全连接的神经网络图. 1前向传 ...
- html5自定义标签选择器
* E[attr]:只使用属性名,但没有确定任何属性值 * E[attr="value"]:指定属性名,并指定了该属性的属性值.必须和元素的属性完全匹配 * E[attr~=&qu ...
- 提升网站用户体验—WebP 图片的高效使用
一.WebP 的由来 现代图像压缩技术对我们的生活方式影响很大.数码相机能将上千张高质量图片存储到一张内存卡里.智能手机可以与邻近设备快速分享高分辨率的图片.网站与手机等移动设备能快速展示各种富媒体. ...
- Zlib压缩算法在Java与Delphi间交互实现(压缩XML交互)
一个典型应用中,使用delphi作为客户端,J2EE服务端,两者之间用XML作为数据交换,为了提高效率,对XML数据进行压缩,为此需要找到一种压缩/解压算法能够两个平台之间交互处理,使用ZLIB算法就 ...
- HTML5区域范围文本框实例页面
CSS代码: input { font-size: 14px; font-weight: bold; } input[type=range]:before { content: attr(min); ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
- 【HDOJ】1455 Sticks
DFS.搜索以棍数为条件循环搜索较好,这样不会超时. #include <stdio.h> #include <string.h> #include <stdlib.h& ...
- Node.js权威指南 (1) - Node.js介绍
1.1 Node.js概述 / 2 1.1.1 使用Node.js能够解决什么问题 / 2 1.1.2 实现高性能服务器 / 2 1.1.3 非阻塞型I/O及事件环机制 / 2 1.1.4 Node. ...