首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓shapes.xml中的多个形状

安卓shapes.xml中的多个形状
EN

Stack Overflow用户
提问于 2011-04-18 19:26:35
回答 1查看 6K关注 0票数 7

我一直在寻找在单个shapes.xml中定义不同形状的可能性,并在一些特定事件中引用每个形状。

我终于找到了我的问题的答案。答案是使用level-list。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
          
        <gradient android:startColor="#aaa" 
            android:endColor="#eee" android:angle="270" />
           
        <corners android:bottomRightRadius="7dp"
            android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
            android:topRightRadius="7dp" />
    </shape>

</item>
<item android:maxLevel="1">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
          
        <gradient android:startColor="#eee" android:centerColor="#ddd"
            android:endColor="#00fff2" android:angle="270" />
           
        <corners android:bottomRightRadius="7dp"
            android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
            android:topRightRadius="7dp" />
    </shape>
</item>
</level-list>

将此应用于样式中的背景属性。可以通过设置该元素的级别来实现不同形状的互换。

例如:findViewById(R.id.mybutton).getBackground().setLevel(1);

在上面的代码中,我将第二个形状设置为id为mybutton的按钮。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-18 19:33:12

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dip" android:color="#FF8000" />
    <solid 
        android:color="#00FFFFFF"
        android:paddingLeft="10dip"
        android:paddingTop="10dip"/>
    <corners android:radius="10px"/>

    <padding 
        android:left="10dip" 
        android:top="10dip" 
        android:right="10dip" 
        android:bottom="10dip" /> 
</shape>

您可以将此用于Boarder和任何形状..its的参考...‘’如果有用,那么接受答案并对答案进行投票。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5702143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档