在首选项屏幕xml中使用静态字段

时间:2011-12-19 18:58:38

标签: android xml preferenceactivity

是否可以在xml中使用静态字段?

来自代码

“customerId”

public class Const {

    public static final String EXTRA_CUSTOMER_ID = "customerId";
}

在首选项xml中作为键名:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="@string/setup">
        <EditTextPreference android:key="customerId" android:summary="..."      android:title="@string/lb_customer_id" />
    </PreferenceCategory>
</PreferenceScreen>

1 个答案:

答案 0 :(得分:0)

如果您尝试在此常量中保存字符串,则可以使用文件&#34; res / values / strings.xml&#34;。

的strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="lb_customer_id">customerId</string>
</resources>

要获取一个strings.xml字符串,您必须使用该方法:

getString(R.strings.lb_customer_id).
希望它有所帮助。