Android ICS 1x1 小部件文本标签

标签 android android-4.0-ice-cream-sandwich android-appwidget

我正在尝试为 ICS 制作一个 1x1 小部件,它在图标下方显示文本标签,并使用设备默认文本样式,但我无法弄清楚这是如何完成的。我知道这是可能的,因为我的 Galaxy Nexus 随附的许多 1x1 小部件都具有此功能。我不想在布局文件中对 textView 进行硬编码,因为这样做会使它在可能使用不同字体和文本大小等的其他设备上看起来很糟糕。

有人知道吗?

最佳答案

我认为您无法绕过将 TextView 放入布局中。您可以做的是从内置的 android 样式之一中为其选择样式。这样它应该匹配所有其他图标/小部件标签。希望这也适用于其他 API 版本,但我知道它在我的 ICS 手机上看起来不错。我也不确定 FrameLayout 是否是这里使用的最佳选择,但我想我会做一些试验。重要的部分是最后的 TextView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/FrameLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >
        <ImageButton
            android:id="@+id/buttonimg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/appwidget_dark_bg_clickable"
            android:clickable="true"
            android:contentDescription="@string/app_name" />
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/app_name"
            android:src="@drawable/arrow_dark" />
    </FrameLayout>
    <TextView
        android:id="@+id/labelTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget"
        android:text="@string/widgetlabeldefault" />
</LinearLayout>

关于Android ICS 1x1 小部件文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11302838/

相关文章:

安卓 string.xml 错误

android - 如何在使用特定版本的功能时使我的项目与不同的 sdk 版本兼容

android - 用于更新小部件的 AsyncTask - 如何访问 onPostExecute() 中的 TextView ?

java - 当我尝试从 EditText 获取文本并将其转换为整数时,应用程序崩溃

java - 当 CL 的高度设置为wrap_Content 时,为什么坐标布局 ( CL ) 会隐藏一半的 float 操作按钮?

android - 在使用 alignParentBottom 的相对布局中,如何在我的代码中的约束布局中使用相同的布局?

android - EditText - inputType =""和 inputType ="text"有什么区别?

java - Android Facebook SDK 使用 OnSelectionChangeListener 获取选定用户时出现问题

android - ListFragment onListItemClick 不再适用于 Android 4.1 Jelly Bean