1

我想在这样的资源中声明一些值:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="Shape">
    <attr name="type" format="enum">
       <enum name="rect" value="0"/>
       <enum name="circle" value="1"/>        
       <enum name="square" value="2"/>        
       </attr>
 </declare-styleable>

在布局中像这样使用它们:

<view       
  class="org.frame_lang.saveandloadhierarchydemo.view.SelectShapeScreenView$Shape" 
    android:id="@+id/rectangleBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    framelang:shapeType="rect"
/>

然后能够以某种方式使用 xml decl 在代码中引用实际的枚举 ID。您可以通过以下方式引用该属性:

R.styleable.Shape_shapeType

但似乎无法为实际值做这样的事情:

R.styleable.Shape_shapeType.rect
R.styleable.Shape_shapeType.circle
R.styleable.Shape_shapeType.triangle

谢谢!

4

0 回答 0