Platform: RK3568
OS: Android 12
Kernel: v4.19.206
SDK Versionandroid-12.0-midrkr1


今天是元宵节,先祝读者和自己元宵快乐


需求

Launcher3的hotseat部分默认设置客户要求的几个应用(如explorerchrome等),并且还要添加AllApp按键实现点击进入AllApp界面

实现方法

以下修改均在packages/apps/Launcher3/目录

  1. 设置默认应用
    跟了下代码,根据我们布局应该是在res/xml/default_workspace_5x5.xml中设置的。主要就是在对应位置添加所需应用的favorite,默认是用launcher:uri属性,不过也支持packageName和className添加,这个可以直接从logcat获取,于是我就采用方式添加,方法如下
diff --git a/res/xml/default_workspace_5x5.xml b/res/xml/default_workspace_5x5.xml
index ccdde2ca8..32f2215d1 100644
--- a/res/xml/default_workspace_5x5.xml
+++ b/res/xml/default_workspace_5x5.xml
@@ -23,6 +23,9 @@
         launcher:screen="0"
         launcher:x="0"
         launcher:y="0" >
+        <favorite
+        launcher:packageName="com.android.rk"
+        launcher:className="com.android.rk.RockExplorer" />
         <favorite launcher:uri="#Intent;action=android.intent.action.DIAL;end" />
         <favorite launcher:uri="tel:123" /&gt;
         <favorite launcher:uri="#Intent;action=android.intent.action.CALL_BUTTON;end" /&gt;
@@ -33,6 +36,9 @@
         launcher:screen="1"
         launcher:x="1"
         launcher:y="0" &gt;
+        <favorite
+        launcher:packageName="com.android.chrome"
+        launcher:className="com.google.android.apps.chrome.Main" /&gt;
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MESSAGING;end" />
         <favorite launcher:uri="sms:" />
         <favorite launcher:uri="smsto:" />
@@ -40,6 +46,7 @@
         <favorite launcher:uri="mmsto:" />
     </resolve>
 
+    <!-- ALL APPS
     <resolve
         launcher:container="-101"
         launcher:screen="2"
@@ -48,12 +55,16 @@
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MAPS;end" />
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MUSIC;end" />
     </resolve>
+    -->
 
     <resolve
         launcher:container="-101"
         launcher:screen="3"
         launcher:x="3"
         launcher:y="0" >
+        <favorite
+        launcher:packageName="com.android.settings"
+        launcher:className="com.android.settings.Settings" />
         <favorite
             launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_BROWSER;end" />
         <favorite launcher:uri="http://www.example.com/" />
@@ -64,6 +75,9 @@
         launcher:screen="4"
         launcher:x="4"
         launcher:y="0" >
+        <favorite
+        launcher:packageName="android.rk.RockVideoPlayer"
+        launcher:className="android.rk.RockVideoPlayer.RockVideoPlayer" />
         <favorite launcher:uri="#Intent;action=android.media.action.STILL_IMAGE_CAMERA;end" />
         <favorite launcher:uri="#Intent;action=android.intent.action.CAMERA_BUTTON;end" />
     </resolve>
@@ -82,9 +96,10 @@
         launcher:screen="0"
         launcher:x="1"
         launcher:y="-1" >
+            <!--
 	    <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_GALLERY;end" />
 	    <favorite launcher:uri="#Intent;type=images/*;end" />
-
+            -->
     </resolve>
  1. 添加AllApp按键
    这个是之前Android版本效果应该是10.0后就取消了该按键使用直接上拉手势进入allapp界面。我这边的实现主要参考了该文章1方法,由于这是收费专栏我就不写出具体代码了。
    有几个差异之处倒是觉得可以列出来:
  1. 添加AllApp按键在遥控焦点选中时的背景
    第2点添加按键之后功能测试OK,不论是用鼠标还是遥控点击都可以进入AllApp界面。但是有个bug就是我们新增的按键在遥控焦点选中没有出现选中背景,而其他的app可以的,需要添加上去。该功能涉及到了drawable资源的添加,这方面我没什么经验,是我们负责应用的同事帮忙实现的,在此也感谢他的给力支持
    关键是在src/com/android/launcher3/Hotseat.java 里面加了以下代码来设置按键的 background
    allAppsButton.setBackgroundResource(R.drawable.all_apps_button_bg);
    这里的all_apps_button_bg.xml 主要内容
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/bg_celllayout_gray" />
    <item android:state_focused="true" android:drawable="@drawable/bg_celllayout_gray" />
    <item android:state_selected="false" android:drawable="@android:color/transparent" />
    <item android:drawable="@android:color/transparent" />
</selector>

bg_celllayout_gray.xml的主要内容为

<shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="#707382"/>
            <corners android:radius="@dimen/bg_round_rect_radius" />

</shape>

部分drawable资源说明可以参考谷歌官方文档2我们这边用到的是State List和Shape Drawable。

最后实现效果如下
请添加图片描述


欢迎留言讨论,感谢阅读~

参考资料


  1. android 9.0 10.0 Hotseat 添加allapp button ↩︎

  2. Drawable resources ↩︎

  3. 在线取色器 ↩︎

原文地址:https://blog.csdn.net/terry_xiwang/article/details/122947623

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_28478.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注