android手把手教你开发launcher(一)(AndroidStudio版)

auncher,也就是android的桌面应用程序。下图是android2.3的launcher应用程序:

   

接下来我们要开发一个自己的launcher,使其替代系统的默认launcher。
怎样使我们的应用程序成为一个launcher?

下面我们就新建一个叫做SAOLauncher的工程,具体步骤略。创建完工程后整个目录结构如下图:
   

现在我们的AndroidManifest.xml文件这样的:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sljjyy.sao.launcher"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sljjyy.sao.launcher.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>
    </application>
</manifest>
请注意<intent-filter>

</intent-filter>里面的内容。
下面我们在其中添加上以下两行:

<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
此时AndroidManifest.xml文件是这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sljjyy.sao.launcher"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sljjyy.sao.launcher.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

此时运行程序,我们看不到任何特别之处。当按下home键时(模拟器上按下home会调出桌面应用),程序如图:  


我们看到了,我们开发的SAO Launcher跟Xperia主页(索尼的home)出现在了一起。 
重启,我们看到我们自己的程序已经可以作为home来运行了。
ok。 第一步完成了:把我们的应用程序作为home。
总结一下:要把我们的应用程序作为home,只需要在AndroidManifest.xml中添加:
 <category android:name="android.intent.category.HOME" />

 <category android:name="android.intent.category.DEFAULT" />

android手把手教你开发launcher(一)(AndroidStudio版)

android手把手教你开发launcher(二)——列出安装的应用程序

android手把手教你开发launcher(三)——启动安装的应用程序

android手把手教你开发launcher(四)——显示widget

android手把手教你开发launcher(五)——设置壁纸

转自:http://www.bangchui.org/read.php?tid=11694

原本为Eclipse版,本文红色部分为小夜修改部分,查看原文请点击以上链接



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值