我有一個小問題。我想根據我的應用程序的TRIAL/PRO版本在我的應用程序中啓用/禁用某些首選項。Android偏好設置 - 設置自定義背景嗎?
當我禁用某些首選項並且它變灰時,我想添加一些圖標或資源來通知用戶這是PRO功能。
例如,我想看看我喜歡的就像這樣(很簡單的例子難看,但我做到了,在30秒內):
如何做這樣的事情?
非常感謝!
我有一個小問題。我想根據我的應用程序的TRIAL/PRO版本在我的應用程序中啓用/禁用某些首選項。Android偏好設置 - 設置自定義背景嗎?
當我禁用某些首選項並且它變灰時,我想添加一些圖標或資源來通知用戶這是PRO功能。
例如,我想看看我喜歡的就像這樣(很簡單的例子難看,但我做到了,在30秒內):
如何做這樣的事情?
非常感謝!
您可以使用文本和圖像(如圖所示)爲列表項目設置自定義佈局,並根據應用的版本(試用版或專業版)切換圖像的可見性。
下面是創建一個自定義列表視圖
http://www.vogella.com/articles/AndroidListView/article.html
您可以使用一個主題的例子:
在你表現:
<!-- Let Preferences have their own theme -->
<activity
android:name="com.example.app.ACTIVITY_Prefs"
android:theme="@style/Theme.APP.Prefs"
/>
你就必須創建主題叫APP.Prefs
[編輯]
爲了讓喜好自己的佈局:
在你RES /佈局文件夾,把一個新的佈局(隨意做修改)。
我打電話給我的prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="?android:attr/scrollbarSize"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="16dp"
android:gravity="center"
android:orientation="horizontal"
>
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
>
<TextView
android:id="@+android:id/displayTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
/>
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
/>
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:shadowColor="@color/white"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:maxLines="4"
/>
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout
android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="48dp"
android:gravity="center"
android:orientation="vertical"
/>
</LinearLayout>
請注意,我用RES /價值/ colors.xml定義我自己的顏色現在
,在您的首選項文件(我的是res/xml/prefs.xml):
想要自定義的每個首選項都必須指定 (或其他一些,如果說,您需要每種首選項類型的不同顏色或 左右)
android:layout="@layout/prefs"
如果你想改變控件圖標(或分配缺少一個):
android:widgetLayout="@layout/arr_dn"
(這其中包含了繪製佈局)
我知道我可以爲任何東西創建自定義視圖,但是如何爲首選項創建自定義視圖?因爲我真的不知道例如默認偏好填充,頁邊距,文本大小,文本顏色等等......只是試圖找到它們對我來說並不是很好的解決方案,因爲它在不同設備上可能會有所不同。 – qkx
我不明白,你有你的應用程序的首選項屏幕,它顯示您的應用程序中可用的偏好? – gaurav5430
如果您沒有顏色值,文本大小,填充和邊距,則無法爲某些內容創建自定義佈局......就這些了。我沒有這個值,也不知道如何獲得它們(從哪裏?) - 因爲我需要讓我的自定義佈局看起來像默認首選佈局一樣,唯一的區別應該是右邊的一個圖標 – qkx