3

我想在 PreferenceActivity 中提供一个按钮。用户应该能够设置时间(例如通过 TimePicker),但没有 ButtonPreference 或类似的东西。我不想使用 EditTextPreference。

那么我是否必须在 PreferenceActivity 中使用默认按钮并手动保存设置?

问候,

科迪

4

3 回答 3

5

创建DialogPreference包含TimePicker小部件的自定义。无需按钮。应少于 100 行代码。

这是一个示例项目,其中显示了一个自定义ColorPreference.

于 2010-10-20T15:56:26.117 回答
0

您可以将按钮放在 activity_layout.xml 中。例如,如果“Activity_Setup.java”是您的设置活动,“activity_setup.xml”是它的布局,“myprefs.xml”是存储您的偏好布局的文件,那么

您应该将按钮放在列表下的“activity_setup.xml”中,最好放在 TableRow 中,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/llprefs">

<ListView
    android:id="@+id/android:list"
    android:tag="lvprefs"
    android:layout_width="match_parent"
    android:layout_height="0.0dp"
    android:layout_weight="1" >
</ListView>

    <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
     >

    <Button
        android:id="@+id/btRegister"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="@string/IdonothaveA"
        android:onClick="onClick"
         />

    <Button
        android:id="@+id/btForgot"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="@string/Iforgot"
        android:onClick="onClick" />
   <!--  
    <Button
        android:id="@+id/btContact"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="@string/Contact"
        android:onClick="onClick" />
     -->

</TableRow>

于 2012-09-26T07:54:57.593 回答
0
Create a different layout including your custom controls and include ListView on top, see the example below

// extra_settings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">
    <ListView android:id="@android:id/list"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" android:layout_weight="1"/>
    <TextView
            android:id="@+id/feedback"
            android:text="Feedback"
            />
    <Button
            android:id="@+id/about"
            android:text="About"
            />
</LinearLayout>

Once this done, onCreate method of your class which is extended from PreferenceActivity add following line

setContentView(R.layout.settings_extras); //name of your layout


bind OnClickListener

View.OnClickListener feedbackPageRedirect = new View.OnClickListener()
        {
            public void onClick(View v)
            {
                Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback  ");

                startActivity(emailIntent);
            }
        };
于 2011-11-14T14:19:10.830 回答