【问题标题】:Custom view in Dialog Preference对话框首选项中的自定义视图
【发布时间】:2011-12-28 15:51:40
【问题描述】:

如何在扩展的 DialogPreference 中设置自定义样式?

public class AboutDialog extends DialogPreference {
    public AboutDialog(Context oContext, AttributeSet attrs)
    {
        super(oContext,attrs);
            //there is no such a thing like setBackground(int res_id)...
    }
}

在xml中

<com.pak1.pak.About
    android:key="key" android:title="@string/preferences_about"
    android:dialogTitle="@string/preferences_about_title"
    android:dialogIcon="@drawable/app_icon" android:negativeButtonText="@null"
    android:positiveButtonText="@string/ok" />

或者例如是否可以更改按钮的属性?

我有一个确定按钮,例如我想改变这个“确定”按钮的颜色,我该怎么做?

【问题讨论】:

    标签: android android-preferences android-dialog android-gui


    【解决方案1】:

    您覆盖 onCreateDialogView,并返回布局。

    例如,参见 Matthew Wiggins 创建的自定义 DialogPreference 示例。

    http://android.hlidskialf.com/blog/code/android-seekbar-preference

    或者在stackoverflow这里

    Android SeekBarPreference

    【讨论】:

      【解决方案2】:

      设置DialogPreference的背景也可以使用方法

          DialogPreference.setDialogLayoutResource(R.layout.layout1);
      

      和简单的颜色资源,通常在res/values/colors.xml中指定:

          <color name="red">#ffff0000</color>
      

      通过android:background="@color/red"res/layout/layout1.xml 中引用此资源。 (More info about setting a background)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-03
        相关资源
        最近更新 更多