始终显示 PreferenceScreen 的滚动条

发布于 2024-10-05 06:44:24 字数 291 浏览 10 评论 0原文

我已经使用preferences.xml和PreferenceActivity在我的应用程序中定义了首选项。这些设置以类似 ScrollView 的方式呈现在手机中。我想始终显示垂直滚动条。在 Android 1.6 中,它们不会消失,但在 Android 2.2 中,它们会在大约一秒后消失。在 ScrollView 中,我可以使用 android:scrollbarAlwaysDrawVerticalTrack 或 android:scrollbarDefaultDelayBeforeFade 来控制它。如何使用首选项小部件执行此操作?

/P

I have defined preferences in my app using preferences.xml and a PreferenceActivity. The settings are presented in the phone in a ScrollView-like-way. I would like to always show the vertical scrollbars all the time. In Android 1.6 they do not fade away, but in Android 2.2 the fade away after about a second. In a ScrollView I can control this using android:scrollbarAlwaysDrawVerticalTrack or android:scrollbarDefaultDelayBeforeFade. How can I do this with the preference widget?

/P

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

唯憾梦倾城 2024-10-12 06:44:24

这适用于我的 Android 2.3.3 。

public class MyPreferenceActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getListView().setScrollbarFadingEnabled(false);
        ...
    }
    ...
}

This worked for my Android 2.3.3 .

public class MyPreferenceActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getListView().setScrollbarFadingEnabled(false);
        ...
    }
    ...
}
木有鱼丸 2024-10-12 06:44:24

尝试这个,因为当我想对 TextView 执行此操作时,上述建议对我不起作用:

TextView.setScrollbarFadingEnabled(false);

Try this as the above suggestions didn't work for me when I wanted to do this for a TextView:

TextView.setScrollbarFadingEnabled(false);
≈。彩虹 2024-10-12 06:44:24

PreferenceScreen 中尝试 android:scrollbarAlwaysDrawVerticalTrack="true"

Try android:scrollbarAlwaysDrawVerticalTrack="true" in the PreferenceScreen.

最笨的告白 2024-10-12 06:44:24

所以,嘿,这是一个非常丑陋的解决方案,但它很短而且很有效。

public class PreferenceActivity extends Activity {
//Sorry for stupid variable names, couldn't be bothered to be smart
    private ScrollView svOptions;
    private Runnable _run_sb_on;
    private final Handler _handle_sb_on = new Handler(); 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preference);

        svOptions = (ScrollView) findViewById(R.id.svOptions);
        _run_sb_on = new Runnable() { //i hate you google for making me write crap code ! 
            public void run() {
                svOptions.fling(0); //don't move it, just keep it alive
                _handle_sb_on.postDelayed(this, 300); //300 is the timeout of the fader 
            }
        }; 
        _handle_sb_on.post(_run_sb_on);
    }

    //  etc

}

这样你就得到了。请注意,投掷可以吃掉触摸事件,这种情况很少见,但有点烦人 - 但可行。

So hey, this is a seriously ugly solution, but its short and it works.

public class PreferenceActivity extends Activity {
//Sorry for stupid variable names, couldn't be bothered to be smart
    private ScrollView svOptions;
    private Runnable _run_sb_on;
    private final Handler _handle_sb_on = new Handler(); 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preference);

        svOptions = (ScrollView) findViewById(R.id.svOptions);
        _run_sb_on = new Runnable() { //i hate you google for making me write crap code ! 
            public void run() {
                svOptions.fling(0); //don't move it, just keep it alive
                _handle_sb_on.postDelayed(this, 300); //300 is the timeout of the fader 
            }
        }; 
        _handle_sb_on.post(_run_sb_on);
    }

    //  etc

}

So there you have it. Note that the fling can eat on-touch events, its rare but its a little annoying - but workable.

如梦初醒的夏天 2024-10-12 06:44:24

将其放在您想要始终显示滚动条的滚动条中:

android:scrollbarFadeDuration="0"

我知道违反直觉,但它工作得很好。

Put this in the scroller that you want to show scrollbars all the time:

android:scrollbarFadeDuration="0"

Counterintuitive, I know, but it works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文