Using shape drawable as my background xml

前端 未结 5 746
悲&欢浪女
悲&欢浪女 2020-12-29 23:06

I really appreciate if someone can help me with using how to use shape drawable as my background xml for my view.

This is what I tried: But I never get the color. An

5条回答
  •  旧时难觅i
    2020-12-29 23:40

    OK - I'm pretty sure my problem is the same as what drove your question, and that I've found its cause.

    The problem is conflicting resource definitions (specifically, resource filenames). Say, for example, for some reason you put a file named "drawable_bg.png" in /res/color/ in your project; and forgot that you did this (or it happened accidentally). If you then try to define a Shape Drawable in your project named "res/drawable/dialog_bg.xml" - the PNG (from 'MyLib') takes precedence. Since you can have many "res" folders for different DPI, form-factor, SDK, etc - it's fairly easy to wind up with a filename collision. This can also happen with Android Library projects. If your project has any dependencies on projects which themselves have resources, they can cause conflicts. As I just found today, Eclipse can either hide or fail to show a warning about this in many situations.

    When this happens it can easily appear that the Shape Drawable is not applied. Since "dialog_bg.png" probably isn't designed for your view you get unexpected results and it's easy to be confused about what's really going on.

    The easiest way to solve this is to rename the shape drawable in your project. If the problem is with a resource(s) in an Android Library Project, then there may be a better solution found by applying the recommended practice as described at http://tools.android.com/recent/buildchangesinrevision14.

提交回复
热议问题