launcher3的hotseat的图标文字处理

本文详细介绍了如何在Android Launcher3应用中调整文件夹图标和All Apps按钮的文字显示,包括隐藏文件夹标题、显示未在快捷栏中的文件夹标题以及All Apps按钮的文字修改和样式调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

隐藏文件夹图标的 标题文字

packages\apps\Launcher3\src\com\android\launcher3\Workspace.java

void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY,
            boolean insert, boolean computeXYFromRank) {

...

            // Hide folder title in the hotseat
            if (child instanceof FolderIcon) {
                ((FolderIcon) child).setTextVisible(false);
            }

            if (computeXYFromRank) {
                x = mLauncher.getHotseat().getCellXFromOrder((int) screenId);
                y = mLauncher.getHotseat().getCellYFromOrder((int) screenId);
            } else {
                screenId = mLauncher.getHotseat().getOrderInHotseat(x, y);
            }
        } else {
            // Show folder title if not in the hotseat
            if (child instanceof FolderIcon) {
                //((FolderIcon) child).setTextVisible(true);
                ((FolderIcon) child).setTextVisible(false); //modefied by xun 
            }

...

}


添加快捷键图标的 标题文字

packages\apps\Launcher3\src\com\android\launcher3\CellLayout.java

 public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,
            boolean markCells) {

...

        // Hotseat icons - remove text
        if (child instanceof BubbleTextView) {
            BubbleTextView bubbleChild = (BubbleTextView) child;
           // bubbleChild.setTextVisibility(!mIsHotseat);

bubbleChild.setTextVisibility(true);   //true为显示
        }

...

}

如果还是没有显示那是因为hotseat高度太小了.packages\apps\Launcher3\src\com\android\launcher3\DynamicGrid.java

// Hotseat
        hotseatBarHeightPx = iconSizePx + 25 * edgeMarginPx;//设置高度


添加allAppsbutton 文字

packages\apps\Launcher3\src\com\android\launcher3\Hotseat.java

    void resetLayout() {

            LayoutInflater inflater = LayoutInflater.from(context);
            TextView allAppsButton = (TextView)
                    inflater.inflate(R.layout.all_apps_button, mContent, false);
            Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
            Utilities.resizeIconDrawable(d);
            allAppsButton.setCompoundDrawables(null, d, null, null);

            allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
            allAppsButton.setText(context.getString(R.string.all_apps_button_label));  //添加文字

}

all_apps_button.xml 文件修改

<item name="android:textSize">28dp</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">3</item>

<item name="android:shadowRadius">4.0</item>
<item name="android:shadowColor">#ee000000</item>

以上这样,虽然能把文字显示出来,但是发现文字的大小和位置都和其他的图标不一样,整体看起来很别扭。所以还要修改下

由于launcher桌面的图标文字是有类 BubbleTextView 完成的,所以在这里让 allAppsButton 继承 BubbleTextView 而不是原先的TextView 。

如下:

    void resetLayout() {
        mContent.removeAllViewsInLayout();
        if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
            // Add the Apps button
            Context context = getContext();
            LayoutInflater inflater = LayoutInflater.from(context);
            BubbleTextView allAppsButton = (BubbleTextView)
                    inflater.inflate(R.layout.all_apps_button, mContent, false);
            Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
            Utilities.resizeIconDrawable(d);
            allAppsButton.setCompoundDrawables(null, d, null, null);
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
allAppsButton.setCompoundDrawablePadding((int) ((grid.folderIconSizePx - grid.iconSizePx) / 2f)); 
allAppsButton.setText(context.getString(R.string.all_apps_button_label));  //
            allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));

...

}

packages\apps\Launcher3\res\layout\all_apps_button.xml

<com.android.launcher3.BubbleTextView 

   xmlns:android="http://schemas.android.com/apk/res/android"
   style="@style/WorkspaceIcon"
   android:focusable="true"
   android:background="@drawable/focusable_view_bg" />


这样就和旁边的一样来了。




### Launcher3 Hotseat 数据库实现与配置 #### 1. 数据库的创建与初始化 Launcher3 的数据库通过 `ContentProvider` 创建,具体实现在 `LauncherProvider` 类中完成。该类继承自 Android 的 `ContentProvider` 并提供了对数据库的操作接口[^1]。为了支持 Hotseat 功能,数据库表结构设计需包含专门用于存储 Hotseat 数据的部分。 Hotseat 数据通常与其他 Workspace 数据共享同一张表,但在实际使用时会区分不同的视图区域(如 Hotseat 和 Workspace)。这种设计可以通过字段标记来实现,例如增加一个额外列表示项属于哪个区域(Hotseat 或 Workspace),从而简化查询逻辑[^2]。 --- #### 2. Hotseat 数据绑定过程 Hotseat 数据的绑定流程类似于 Workspace 数据绑定,主要区别在于数据源的选择和 UI 布局的应用。以下是具体的绑定机制: - **清空现有数据** 当 Hotseat 开始绑定时,其内部方法会被调用来清除当前的数据状态。这一步骤确保每次加载都能获取最新的配置信息。 - **加载新数据** 新数据由模型层的任务类(如 `LoaderTask`)负责加载并填充到对应的 View 中。这些任务类会读取数据库中的记录,并将其映射为可视化的图标或组件[^4]。 --- #### 3. 配置 XML 文件的作用 对于 Hotseat 的初始布局定义,可以借助 XML 文件进行静态配置。例如,在 Android 11 及更高版本中,`default_workspace_5x5.xml` 是一种常见的默认工作区布局文件,其中可能也包含了 Hotseat 区域的相关设置[^5]。 以下是一个简单的 XML 示例片段: ```xml <item xmlns:android="http://schemas.android.com/apk/res/android" container="hotseat" screen="0"> <appwidget /> </item> ``` 上述代码指定了某个应用小部件应放置于 Hotseat 上的第一个屏幕位置。开发者可以根据需求调整此类配置以满足特定场景下的定制化要求。 --- #### 4. 关键类的功能描述 在实现过程中涉及的关键类及其作用如下: - **`AutoInstallsLayout.java`**: 负责解析预设的工作区布局文件,并将相关内容写入数据库。 - **`LoaderTask.java`**: 执行异步加载任务,从数据库提取所需数据并将它们传递给前端界面渲染模块。 - **`AddWorkspaceItemsTask.java`**: 处理新增项目至工作空间的具体事务处理逻辑。 以上各部分协同合作共同完成了整个 Hotseat 数据管理生命周期的支持。 --- #### 5. 总结 综上所述,Launcher3 对于 Hotseat 的数据库实现主要包括以下几个方面:基于 ContentProvider 构建统一的内容访问入口;利用 SQLiteOpenHelper 完成底层持久化操作;并通过一系列辅助工具类配合完成动态更新及展示等功能扩展[^3]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值