我已經在真實手機中安裝了我的應用程序,即使在模擬器中, 首選項彙總的所有文本看起來都是相同的顏色,但在真實手機中,顏色不同(某種藍色...但我想這取決於手機的型號)。Android偏好摘要默認顏色?
如何將此顏色設置爲我的自定義首選項組件? (我已經實現了我自己的搜索欄,其摘要文本顏色不同於其他所有組件的文本顏色...)。
謝謝!
我已經在真實手機中安裝了我的應用程序,即使在模擬器中, 首選項彙總的所有文本看起來都是相同的顏色,但在真實手機中,顏色不同(某種藍色...但我想這取決於手機的型號)。Android偏好摘要默認顏色?
如何將此顏色設置爲我的自定義首選項組件? (我已經實現了我自己的搜索欄,其摘要文本顏色不同於其他所有組件的文本顏色...)。
謝謝!
我發現這些:android:textAppearance="?android:attr/textAppearanceLarge"
和android:textAppearance="?android:attr/textAppearanceSmall"
似乎做的伎倆。
我不認爲這是可能的。我可以更改背景顏色和標題文字顏色,但不能更改摘要顏色。
背景:
getListView().setBackgroundColor(Color.TRANSPARENT);
標題文字:
Preference yourpreference = findPreference("yourpreference");
TextView tv = (TextView)yourpreference.getView(null, getListView());
tv.setTextColor(...);
很抱歉我不能幫助更多...
Samsung Galaxy S手機具有其自己的首選項佈局,其中爲摘要行指定了文本顏色。即使指定了TextAppearance.Small,佈局的textColor屬性也會覆蓋文本外觀。
Preference pUpdate = findPreference("sys_setting_update");
pUpdate.setSummary(Html.fromHtml("<font color=\"#B0C4DE\">This is content</font>"));
使用Html.fromHtml("<font color=\"#B0C4DE\">This is content</font>")
到setSummary
我已經找到了一種方法來檢索您的應用程序運行在Android設備使用的默認顏色。這是一個有點棘手,您檢索到的色感requieres從您的活動的另一首選摘要視圖中顯示,並將其存儲在運行時。
然後,您可以在其他視圖中使用與其他偏好相同的顏色代碼,以確保您將會獲得Android分配給標準偏好設置的相同顏色代碼。以下是我如何做到的:
我的首選項活動有一個正常的CheckBoxPreference,用於激活或停用服務。我已經擴展CheckBoxPreference如下,讓我在擴展檢索rutime默認顏色的Android終於給到CheckBoxPreference摘要:
public class MyCheckBoxPreference extends android.preference.CheckBoxPreference {
private static int sSummaryColor = Color.WHITE;
private static boolean sInitialized = false;
public MyCheckBoxPreference(Context context) {
super(context);
}
public MyCheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onBindView(View view) {
super.onBindView(view);
if (!sInitialized) {
sSummaryColor = getSummaryColor(view);
sInitialized = true;
}
}
private int getSummaryColor(View view) {
int color = Color.WHITE;
// Gets the color android gave to the summary by default
TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
if (summaryView != null) {
ColorStateList list = summaryView.getTextColors();
if (list != null) {
color = list.getDefaultColor();
}
}
return color;
}
public static int getSummaryColor() {
return sSummaryColor;
}
}
在我的preferences.xml我實例化偏好MyCheckBoxPreference,而不是僅僅CheckBoxPreference:
<org.yourpackage.MyCheckBoxPreference
android:title="@string/preference_title_activate"
android:defaultValue="false"
android:summary="@string/preference_summary_activate_off"
android:summaryOff="@string/preference_summary_activate_off"
android:key="preference_activate">
</org.yourpackage.MyCheckBoxPreference>
MyCheckBoxPreference必須在使用MyCheckBoxPreference.getSummaryColor()檢索彙總顏色之前實例化一次。
現在,您可以設置其他定製的喜好從onBindView(查看)顏色:
public class MyCustmizedPreference extends Preference {
public MyCustmizedPreference (Context context) {
super(context);
setLayoutResource(R.layout.my_customized_preference);
}
@Override
public void onBindView(View view) {
super.onBindView(view);
TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
if (summaryView != null) {
summaryView.setTextColor(MyCheckBoxPreference.getSummaryColor());
}
}
}
它實際上是在三星Galaxy S.作品我也測試了它不會破壞模擬器下任何東西。
您的代碼幫助我使用onBindView()更改ICS中ListPreference的SpannableString無法執行的摘要的文本顏色。 – Tomcat 2013-01-05 01:46:23
我有同樣的問題,我一直在試用我自定義的seekbar-preference樣式。終於在seekBarPreference.java
onCreateView
方法,這些線顯示偏好與默認的文本顏色摘要:
TextView summaryText = new TextView(getContext());
summaryText.setText(getSummary());
summaryText.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
我用它在preference_screen.xml
:
<com.asdasf.SeekBarPreferencias
android:key="@string/pref_seekBar_distance_key"
android:id="@+id/mySeekBarPreference"
android:title="@string/pref_seekBar_distance_title"
android:summary="@string/pref_seekBar_distance_summary"
android:max="50"
android:defaultValue="12"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
我希望這將是有益的。(和我有寫得很好,我的第一個回答) 注意!
顏色資源是否正常? :http://developer.android.com/guide/topics/resources/providing-resources.html – ykatchou 2010-11-02 21:08:50
我們已經嘗試將文本的顏色設置爲android.R.color.white;例如,但它只是變黑。 – Jason 2010-11-03 20:07:44
你有沒有嘗試過別的東西比android.R.color資源。這將是愚蠢的,但製造商可以改變這些價值......它會影響設備上安裝的每個應用程序。嘗試一下自定義的值,如#fff。 – grattemedi 2010-11-09 17:07:06