gpt4 book ai didi

android - SeekBar setMin 在 Android 中至少需要 api 26?

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:14 25 4
gpt4 key购买 nike


我想在我的 android 应用程序中使用 SeekBar。我的minsdk版本必须是23。编译器说 SeekBar 的 setMin 至少需要 API 级别 26。我需要一些特殊的支持库来实现简单的 SeekBar setMin 吗?

我在 Linux 上使用 Android Studio 3.0.1。我的 build.gradle 是这样的:

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.zamek.boyler"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

我的布局 fragment :

<SeekBar
android:id="@+id/sb_hysteresis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"/>

我的 Activity 代码 fragment :

import android.widget.SeekBar;
...
private SeekBar hysteresis;
...
this.hysteresis = findViewById(R.id.sb_hysteresis);
this.hysteresis.setMin(10); <--Compiler said:Call requires API level 26 (current min is 23): android.widget.AbsSeekBar#setMin

谢谢,
扎梅克

最佳答案

SeekBar 在 API 级别 26 中添加了 setMin() 方法。

如果你想限制你的 SeekBar 最小值,那么你必须手动实现它。

 seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int min = 5;
if(progress < min) {
seekBar.setProgress(min);
}

}

关于android - SeekBar setMin 在 Android 中至少需要 api 26?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48479842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com