Android 偏好设置摘要默认颜色?
我已经在真正的手机中安装了我的应用程序,即使在模拟器中的所有文本 偏好摘要似乎是相同的颜色,在真正的手机中,颜色是不同的(某种蓝色......但我想这取决于手机的型号)。
如何将此颜色设置为我的自定义首选项组件? (我已经实现了自己的搜索栏,其摘要文本颜色与所有其他组件文本颜色不同......)。
谢谢!
I have installed my app in a real phone, and even though in the emulator all the texts of the
preferences summaries seem to be in the same color, in the real phone the color is different (some kind of blue... but I guess it depends on the phone's model).
How can I set this color to my custom preference component?
(I have implemented my own seek bar, and its summary text color is different from all the other components text color...).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用
Html.fromHtml("This is content")
来设置Summaryuse
Html.fromHtml("<font color=\"#B0C4DE\">This is content</font>")
to setSummary我找到了这些:
android:textAppearance="?android:attr/textAppearanceLarge"
和 android:textAppearance="?android:attr/textAppearanceSmall"
似乎可以解决问题。
I found these:
android:textAppearance="?android:attr/textAppearanceLarge"
and
android:textAppearance="?android:attr/textAppearanceSmall"
seem to do the trick.我已经找到了一种方法来检索运行应用程序的 Android 设备使用的默认颜色。这有点棘手,并且需要您从 Activity 的另一个首选项摘要视图中检索显示的颜色并将其存储在运行时。
然后,您可以在其他首选项的其他视图中使用相同的颜色代码,确保您始终获得分配给标准首选项的相同颜色代码。我是这样做的:
我的首选项活动有一个正常的 CheckBoxPreference,我用它来激活或停用服务。我扩展了 CheckBoxPreference,如下所示,因此我的扩展在 rutime 中检索 Android 最终赋予该 CheckBoxPreference 的摘要的默认颜色:
在我的preferences.xml 中,我将该首选项实例化为 MyCheckBoxPreference,而不仅仅是 CheckBoxPreference:
MyCheckBoxPreference 必须在之前实例化一次使用 MyCheckBoxPreference.getSummaryColor() 检索摘要颜色。
现在您可以从 onBindView(View) 设置其他自定义首选项的颜色:
它实际上可以在 Samsung Galaxy S 下运行。我还测试过它在模拟器下不会破坏任何内容。
I have figured out a way to retrieve the default color used by the Android device your application is running in. It is a bit tricky and requieres that you retrieve the color being shown from another Preference Summary View of your activity and store it in runtime.
Then you can use the same color code in other Views of other preferences, assuring that you will allways get the same color code Android assigned to the standard preferences. Here is how I did it:
My preferences activity has a normal CheckBoxPreference that I use to activate or deactivate a service. I have extended CheckBoxPreference as follows, so my extension retrieves in rutime the default color Android finally gave to the summary of that CheckBoxPreference:
In my preferences.xml I instantiate that preference as MyCheckBoxPreference instead of just CheckBoxPreference:
The MyCheckBoxPreference has to be instantiated once before retrieving the summary color with MyCheckBoxPreference.getSummaryColor().
Now you can set the color of other customized preferences from onBindView(View):
It actually works under Samsung Galaxy S. I have also tested that it doesn't break anything under the emulator.
Samsung Galaxy S 手机有自己的首选项布局,并为摘要行指定了文本颜色。即使指定了 TextAppearance.Small,布局的 textColor 属性也会覆盖文本外观。
The Samsung Galaxy S phones have their own Preference layout with the text color specified for the Summary line. Even though a TextAppearance.Small is specified the textColor attribute of the layout is overriding the text appearance.
我认为这是不可能的。我可以更改背景颜色和标题文本颜色,但不能更改摘要颜色。
背景:
标题文字:
抱歉,我无法提供更多帮助......
I don't think this is possible. I am able to change the background color and the title text color, but not the summary color.
Background:
Title text:
Sorry I couldn't help more...
我遇到了同样的问题,并且一直在尝试自定义搜索栏首选项的样式。最后,
seekBarPreference.java
的onCreateView
方法中的这些行以默认文本颜色显示首选项摘要:我在
preference_screen.xml
上使用它:我希望它会有用的...(而且我的第一个答案写得很好)
看待!
I had the same problem and I've been experimenting with my custom seekbar-preference's style. Finally these lines in
onCreateView
method ofseekBarPreference.java
show preference's summary with default text color:I use it on
preference_screen.xml
:I hope it will be useful...(and that I have written well my first answer)
Regard!