我已经在真实手机中安装了我的应用程序,即使在模拟器中, 首选项汇总的所有文本看起来都是相同的颜色,但在真实手机中,颜色不同(某种蓝色...但我想这取决于手机的型号)。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