gpt4 book ai didi

Android 主屏幕小部件(图标、标签 - 样式)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:47 25 4
gpt4 key购买 nike

我正在尝试创建一个可以放置在 android 主屏幕上的图标/小部件(1 个单元格 x 1 个单元格)。该小部件的外观和行为与 android 中的其他标准快捷方式完全一样。它将有一个图标,在该图标下方有一个标签,可以使用轨迹球选择它(能够突出显示),当它被选中/单击时它会突出显示。

我该如何着手创建这个主屏幕小部件?

我是否必须自己使用代码/xml 创建小部件,或者是否有一些标准的 xml、样式、主题、代码可用于确保该小部件与其他主屏幕小部件具有相同的样式/主题?

我目前有以下内容

res/drawable/corners.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Corners">
<stroke android:width="4dp" android:color="#CC222222" />
<padding android:left="4dp" android:top="1dp" android:right="4dp" android:bottom="1dp" />
<corners android:radius="4dp" />
</shape>

res/layout/widget.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Widget"
android:layout_width="72dip"
android:layout_height="72dip"
android:orientation="vertical"
android:focusable="true"
android:gravity="center_horizontal"
style="@android:style/Widget"
>

<ImageView
android:id="@+id/WidgetIcon"
android:src="@drawable/icon"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:paddingTop="3dip"
android:gravity="center"
/>

<TextView
android:id="@+id/WidgetLabel"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/app_name"
android:textSize="15dip"
android:background="@drawable/corners"
/>

</LinearLayout>

生成的小部件看起来有些接近,但它不可选择,单击时不会突出显示,并且标签不在正确的位置或正确的样式中。

任何想法,如果有正确的方法来做到这一点,还是我应该继续努力直到我更接近?

最佳答案

“执行此操作的正确方法”是创建快捷方式,而不是尝试使用应用小部件来模仿它。 Android 核心团队(特别是 Romain Guy)在 [android-developers] 讨论列表中反复指出了这一点,such as :

Widgets should look like widgets, not like shortcuts. The main reason is that there is absolutely NO guarantee about what a shortcut will look like. Other devices (especially ones with custom system UIs like MOTOBLUR or HTC Sense) might have a different look and feel. Or in the next update of Android we might change the way shortcuts are presented.

关于Android 主屏幕小部件(图标、标签 - 样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2651631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com