Android - Can't create simple rectangle shape… UnsupportedOperationException?

前端 未结 1 1604
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 18:35

I\'m having trouble creating a simple rounded rectangle using XML. Every time I try to add the \"corners\" element to the custom shape I get:

java.lan

相关标签:
1条回答
  • 2021-01-11 18:39

    So, I was just playing around with this a bit and I changed a couple of lines in the rounded_rectangle.xml to get it working. See below:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
        <solid android:color="#ffffff"/>    
    
        <stroke android:width="3dp"
                android:color="#ff000000"/>
    
        <padding android:left="1dp"
                 android:top="1dp"
                 android:right="1dp"
                 android:bottom="1dp"/> 
    
        <corners android:radius="30dp"/> 
    </shape>
    

    I only wish Google would put out a proper reference doc for creating XML-based shapes. After hours (4+) of hunting down examples on the Web, I feel like it's still a guessing game as to what elements/attributes are supported in these types of XML documents. Sorry for the mini-rant.

    I hope this helps someone else.

    0 讨论(0)
提交回复
热议问题