Defining XML Parent Style of Gradient / Shape / Corners

坚强是说给别人听的谎言 提交于 2019-11-30 09:12:06

Unfortunately I don't think it is possible. I tried to do the same thing and could not find a solution.

What I would suggest is putting all your values in resource xml files. In my case I chose to put my dimensions in dimens.xml, & integers.xml and colours in colours.xml (though they could have been combined into one file)

While I ended up with a shape drawable file for each colour, at least if I want to tweak colours or padding etc I only need to edit the colours.xml file integers.xml or dimens.xml file.

One of my shape drawable then looked like this:

<?xml version="1.0" encoding="UTF-8"?>

<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle" >

  <corners 
      android:radius = "@dimen/radius_corner" />

  <!-- end colour at top, start colour at bottom -->
  <gradient
      android:angle="@integer/gradient_angle_default"
      android:endColor="@color/white" 
      android:startColor="@color/pink_pale"/>

  <padding
      android:left = "@dimen/my_padding"
      android:right = "@dimen/my_padding"
      android:bottom = "@dimen/my_padding"
      android:top = "@dimen/my_padding"  />

</shape>

Resource file link: http://developer.android.com/guide/topics/resources/more-resources.html

Hope this helps.

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