gpt4 book ai didi

android - android 中 shapes.xml 中的多个形状

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:51 24 4
gpt4 key购买 nike

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

我终于找到了解决问题的方法。答案是使用级别列表。

<?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 的按钮。

最佳答案

<?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 和任何形状..它供引用...''如果有用,请接受答案并投票给答案

关于android - android 中 shapes.xml 中的多个形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5702143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com