Light与全息父主题

Light与全息父主题

本文介绍了继承EDITTEXT从Theme.Light与全息父主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想继承 EDITTEXT 安卓主题,而我的父母的主题是机器人:Theme.Holo.Light
。是否有干​​净的方式来做到这短短的复制从Android SDK文件夹中的资源投入到我的项目?

I want to inherit the editText from android:Theme while my parent theme is android:Theme.Holo.Light.
Is there any "clean" way to do this short of copying the resources from the android sdk folder into my project?

推荐答案

所以我的想法是有一个自定义的主题(实际上只是一种风格),从扩展的android:Theme.Holo.Light ,然后覆盖的EditText 属性从 Android的使用父设置:主题

So my idea would be to have a custom theme (really just a style) that extends from android:Theme.Holo.Light, and then overwrites the EditText attributes to use the parent settings from android:Theme.

看起来安卓Theme.Holo.Light 使用了 editTextStyle 属性参照改变的外观 EditTexts

It looks like android:Theme.Holo.Light uses an editTextStyle attribute reference to change the appearance of the EditTexts:

<item name="editTextStyle">@android:style/Widget.Holo.Light.EditText</item>

所以,你可以用 editTextStyle Android的覆盖之:主题

<style name="YourTheme" parent="android:Theme.Holo.Light">
    <item name="android:editTextStyle">@android:style/Widget.EditText</item>
</style>

然后,所有你需要做的就是使用 YourTheme 在你的清单(或code,如果你真的想)让你的自定义主题。您可能需要进一步调整的东西,检查出所有的股票主题在这里:https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

Then, all you have to do is apply YourTheme in your manifest (or in code if you really want to) to get your custom theme. You may want to tweak stuff further, check out all the stock themes here: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

我刚刚测试了这一点,并意识到它看来,安卓风格/ Widget.EditText 似乎并没有从旧版本的机器人,最有可能的应用背景因为它使用了引用安卓editTextBackground ,其中 Holo.Light 集。我只是尝试也在不断变化安卓editTextBackground 手动遗留的EditText 绘制,这对我的作品。

I just tested this out and realized that it appears that android:style/Widget.EditText doesn't seem to apply the background from older versions of android, most likely because it uses a reference to android:editTextBackground, which Holo.Light sets. I just tried also changing android:editTextBackground manually to the legacy EditText drawable, and it works for me.

注:仅适用于本次调整在 styles.xml /值-V11 ,因为只有3.0版本,可以使用安卓editTextBackground ,和旧版本的Andr​​oid将已使用旧的EditText 背景。如果应用程序min为> = 11 API,你不必担心这一点。

Note: Only apply this adjustment on your styles.xml under /values-v11, since only version 3.0 and can use android:editTextBackground, and older versions of android will already use the old EditText background. If the app min is >= API 11, you don't need to worry about this.

<style name="YourTheme" parent="android:Theme.Holo.Light">
    <item name="android:editTextStyle">@android:style/Widget.EditText</item>
    <item name="android:editTextBackground">@android:drawable/edit_text</item>
</style>

这篇关于继承EDITTEXT从Theme.Light与全息父主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:16