如何从 "declare-styleable" 中获取双倍值

How to get double value from "declare-styleable"

如何从 declare-styleable 获得 double 值?

attributes.xml

<declare-styleable name="MeterView">
    <attr name="volume" format="double"/> // Can't resolved format
</declare-styleable>

为 meterView 赋双精度值

<com.test.example.MeterView
    android:id="@+id/meter1"
    android:layout_width="295dp"
    android:layout_height="150dp"
    app:volume="123456789.01"/>

呼叫attributes.xml

Double volume = a.getDouble(R.styleable.MeterView_volume); // Can't resolved getDouble

在 attributes.xml 文件中使用 float 而不是 double。不允许加倍。

<declare-styleable name="MeterView">
        <attr name="volume" format="float"/> 
</declare-styleable>

a.getFloat(R.styleable.MeterView_volume);

在运行时使用字符串并将字符串转换为双精度。

<declare-styleable name="MeterView">
            <attr name="volume" format="string"/> 
 </declare-styleable>

double d= Double.parseDouble(a.getString(R.styleable.MeterView_volume));