Android theme not being set

家住魔仙堡 提交于 2019-11-28 09:04:32
Ana M

I've been struggling with this as well, and think I've finally found what may have been the problem - perhaps it is the same.

I had the custom theme defined in the res\values folder, but not in the values-v11 and values-v14 folders. Which I think made it so that in some devices (specially the 2 I was testing with!), the theme could not be applied because it did not exist.

I now see the properties set in my custom theme (applied at the application level) taking effect.

I had to explicitly define theme for every <activity>.

Paul Lammertsma

According to this answer, it appears that it isn't possible to provide layout_width and layout_height through styles. While it compiles, the exception it raises is:

E/AndroidRuntime(4117): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example/com.example.MainActivity}:
java.lang.RuntimeException: Binary XML file line #79: You must supply a
layout_width attribute.

I'm not sure why that is, but there might be a workaround. As this question suggests, you might be able provide a reference as the width and height parameter.

Again, my experiences are that Android doesn't properly support providing the widget dimensions through styles.

Just out of curiosity. Try renaming your Theme to something else like FooBar.

Going to state the obvious here, but make sure your button is using the right style.

EDIT: I'm not sure if this was just a typo in the question, but in your main theme you reference Android's Theme.Black style incorrectly. Your code says:

<style name="Theme" parent="android:style/Theme.Black">

When it should say:

<style name="Theme" parent="@android:style/Theme.Black">

I feel like Lint or the compiler would bark at you for that before running the application, but maybe that will help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!