首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >自定义首选项,Target tSdkVersion=“11”:缺少缩进如何处理?

自定义首选项,Target tSdkVersion=“11”:缺少缩进如何处理?

提问于 2018-03-16 01:20:29
回答 2关注 0查看 561

我有几个自定义DialogPreference实现浮动,比如:

代码语言:javascript
复制
package apt.tutorial;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TimePicker;

public class TimePreference extends DialogPreference {
    private int lastHour=0;
    private int lastMinute=0;
    private TimePicker picker=null;

    public static int getHour(String time) {
        String[] pieces=time.split(":");

        return(Integer.parseInt(pieces[0]));
    }

    public static int getMinute(String time) {
        String[] pieces=time.split(":");

        return(Integer.parseInt(pieces[1]));
    }

    public TimePreference(Context ctxt) {
        this(ctxt, null);
    }

    public TimePreference(Context ctxt, AttributeSet attrs) {
        this(ctxt, attrs, 0);
    }

    public TimePreference(Context ctxt, AttributeSet attrs, int defStyle) {
        super(ctxt, attrs, defStyle);

        setPositiveButtonText("Set");
        setNegativeButtonText("Cancel");
    }

    @Override
    protected View onCreateDialogView() {
        picker=new TimePicker(getContext());

        return(picker);
    }

    @Override
    protected void onBindDialogView(View v) {
        super.onBindDialogView(v);

        picker.setCurrentHour(lastHour);
        picker.setCurrentMinute(lastMinute);
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        super.onDialogClosed(positiveResult);

        if (positiveResult) {
            lastHour=picker.getCurrentHour();
            lastMinute=picker.getCurrentMinute();

            String time=String.valueOf(lastHour)+":"+String.valueOf(lastMinute);

            if (callChangeListener(time)) {
                persistString(time);
            }
        }
    }

    @Override
    protected Object onGetDefaultValue(TypedArray a, int index) {
        return(a.getString(index));
    }

    @Override
    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
        String time=null;

        if (restoreValue) {
            if (defaultValue==null) {
                time=getPersistedString("00:00");
            }
            else {
                time=getPersistedString(defaultValue.toString());
            }
        }
        else {
            time=defaultValue.toString();
        }

        lastHour=getHour(time);
        lastMinute=getMinute(time);
    }
}

他们工作得很好。但是,在具有已android:targetSdkVersion="11"定义的应用程序中,在XOOM中,它们在下列情况下显示缺少缩进PreferenceActivity

PreferenceActivity与自定义的DialogPreference混淆
PreferenceActivity与自定义的DialogPreference混淆

此外,字体大小显得更大,至少对于标题来说。

没有什么东西可以DialogPreference覆盖任何格式化行为,AFAIK。偏好XML是不起眼的,除了提到上面的类:

代码语言:javascript
复制
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ListPreference
        android:key="sort_order"
        android:title="Sort Order"
        android:summary="Choose the order the list uses"
        android:entries="@array/sort_names"
        android:entryValues="@array/sort_clauses"
        android:dialogTitle="Choose a sort order" />
    <CheckBoxPreference
        android:key="alarm"
        android:title="Sound a Lunch Alarm"
        android:summary="Check if you want to know when it is time for lunch" />
    <apt.tutorial.TimePreference
        android:key="alarm_time"
        android:title="Lunch Alarm Time"
        android:defaultValue="12:00"
        android:summary="Set your desired time for the lunch alarm"
        android:dependency="alarm" />
    <CheckBoxPreference
        android:key="use_notification"
        android:title="Use a Notification"
        android:defaultValue="true"
        android:summary="Check if you want a status bar icon at lunchtime, or uncheck for a full-screen notice"
        android:dependency="alarm" />
</PreferenceScreen>

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档