【问题标题】:How to mark an Icon on the right of a Preference Item in the PreferenceActivity?如何在 PreferenceActivity 中的 Preference Item 右侧标记一个 Icon?
【发布时间】:2011-05-05 03:20:03
【问题描述】:

请点击查看图片 http://i1094.photobucket.com/albums/i455/tdounnyy/device.png

在此 PreferenceActivity 的底部,“选择铃声”右侧有一个图标/按钮。

“振动”不会。

此振动偏好是一种客户偏好扩展偏好。

我想在振动行中放置相同的图标。 一种方法是扩展 ListPreference 或 RingtonePreference 以欺骗操作系统。

我不喜欢这样,想知道是否有更好的解决方案。

preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout used by PreferenceScreen. This is inflated inside 
        android.R.layout.preference. -->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="4dip"
    android:layout_gravity="center_vertical"
    android:background="@drawable/btn_circle"
    android:src="@drawable/ic_btn_round_more" />

我添加前缀“android”为:

android:background="@android:drawable/btn_circle"
android:src="@android:drawable/ic_btn_round_more"

现在,Eclipse 说:错误:资源未公开。 我用谷歌搜索但没有运气。 有想过怎么突破吗?

【问题讨论】:

    标签: android preferenceactivity preference


    【解决方案1】:

    创建首选项 xml 文件时,您可以为首选项指定自定义布局,并且可以在其中放置一个图标。最简单的方法是查看 Android SDK 文件夹:platforms/data//res/layout/(我相信它)包含用于不同首选项类型的实际布局文件:您可能可以从其中复制其中一个在那里并将其用作您自己的自定义偏好的基础。

    【讨论】:

    • 谢谢,这真是一个优雅的解决方案。但是,我面临另一个问题,见上文。回复感谢~~
    • 您不必引用 android 资源(不公开),但您必须逐字复制资源文件并将其添加到您的项目 drawables 集中。
    • @Marcovena 是对的:你必须将它复制到你自己的 res/layout 文件夹中才能使用它,然后它只是一个普通的应用程序资源,而不是一个 android 资源。
    • 我想在整个系统中保持相同的风格。当用户更改主题时,我的应用将与其他应用一样。
    • 这是一个很好的观点:我认为如果您的样式引用 Android 主题颜色,它将适应系统主题的变化。不过,从未尝试过,所以老实说,我无法以一种或另一种方式确认它是如何工作的。
    猜你喜欢
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多