Android ShortCut 方法一:在配置文件中静态声明

方法一:在配置文件中静态声明,shortcut的图标,文字,提示文字,跳转意图,跳转参数等。 

步骤一:在res文件夹中新建xml文件夹,在其中新建shortcuts.xml,按照如下方式写

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    
    <shortcut
        android:enabled="true"
        android:icon="@drawable/ic_short_cut_market"
        android:shortcutDisabledMessage="@string/look_round_market_disable"
        android:shortcutId="market"
        android:shortcutLongLabel="@string/look_round_market"
        android:shortcutShortLabel="@string/look_round_market">

      
        <!--但是这样做比较死板,不能起到管理的作用-->
        <intent
            android:action="android.intent.action.VIEW"
            <!--Activity路径-->
            android:targetClass="com.xxx.activity.act.home.MainActivity"

             <!--给固定intent,添加参数-->
            android:data="zze://xxx.com/main/main?tab=1"

            <!--你的包名-->
            android:targetPackage="com.xxx.activity"/>
    </shortcut>
</shortcuts>

步骤二:在你的launch Activity 中添加元素

<application
    ...
    >

    <activity
            android:name=".SplashAct"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <!--添加shortcuts元素-->
            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts"/>

    </activity>

    ...
</application>

效果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值