有没有一种方法,以一个搜索栏添加到我的实际preference屏幕? [英] Is there a way to add a seekbar to my actual preference screen?

查看:121
本文介绍了有没有一种方法,以一个搜索栏添加到我的实际preference屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看到添加自己的搜索栏preference教程,但它不是在我的实际prefs.xml。有什么办法有一个在我的主要preFS屏幕或我将不得不分开吧。

I keep seeing the tutorial on adding your own seekbar preference, but its not in my actual prefs.xml. Is there any way to have one in my main prefs screen or will I have to separate it.

推荐答案

有似乎是由谷歌2滑块preferences -

There seem to be a 2 slider preferences by Google -

  • SeekBarPreference - inline
  • SeekBarDialogPreference - dialog based

但我不知道,当他们将可用。

but I am not sure when they will be available.

您可以使用自定义的内联的的搜索栏preference 通过我(见底部的滑块2):

You could use a custom inline SeekBarPreference by me (see the 2 sliders at the bottom):

我的code是相当简单 -

My code is quite simple -

<一个href=\"https://github.com/afarber/android-newbie/blob/master/My$p$pfs/src/de/afarber/my$p$pfs/SeekBar$p$pference.java\"相对=nofollow>搜索栏preference.java :

public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {
    private SeekBar mSeekBar;
    private int mProgress;

    public SeekBarPreference(Context context) {
        this(context, null, 0);
    }

    public SeekBarPreference(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SeekBarPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setLayoutResource(R.layout.preference_seekbar);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        mSeekBar = (SeekBar) view.findViewById(R.id.seekbar);
        mSeekBar.setProgress(mProgress);
        mSeekBar.setOnSeekBarChangeListener(this);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (!fromUser)
            return;

        setValue(progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // not used
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // not used
    }

    @Override
    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
        setValue(restoreValue ? getPersistedInt(mProgress) : (Integer) defaultValue);
    }

    public void setValue(int value) {
        if (shouldPersist()) {
            persistInt(value);
        }

        if (value != mProgress) {
            mProgress = value;
            notifyChanged();
        }
    }

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

和<一个href=\"https://github.com/afarber/android-newbie/blob/master/My$p$pfs/res/layout/$p$pference_seekbar.xml\"相对=nofollow> preference_seekbar.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical" >

    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="0dp"
        android:layout_weight="80"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@android:id/summary"
        android:layout_width="0dp"
        android:layout_weight="20"
        android:layout_height="wrap_content" />

</LinearLayout>

这篇关于有没有一种方法,以一个搜索栏添加到我的实际preference屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆