我正在尝试设置动态文本,在拖动搜索栏时,您可以在拖动栏时看到该值。但我没有取得任何成功。
我在stackoverflow中尝试了一些帖子,但我无法做任何事情,它遵循我所处理的代码:
class AccountActivity : LoggedActivity<ViewAccountBinding, AccountViewModelKotlin>() {
// BASE METHODS
....
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var _testText = TextView(this)
_testText.setTextColor(resources.getColor(R.color.black_75))
var currentValue : Int = binding.seekbarAccount.progress
binding.seekbarAccount.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
override fun onProgressChanged(p0: SeekBar?, progress: Int, p2: Boolean) {
currentValue = progress
//just to show dynamic text above thumb of seekbar
var value : Int = (progress * (binding.seekbarAccount.width - 2 * binding.seekbarAccount.thumbOffset))/binding.seekbarAccount.max
_testText.text = ""+progress.toString()
_testText.x = (binding.seekbarAccount.x + value + binding.seekbarAccount.thumbOffset)/2
}
override fun onStartTrackingTouch(p0: SeekBar?) {
//
}
override fun onStopTrackingTouch(p0: SeekBar?) {
viewModel.fontSize = currentValue
Toast.makeText(this@AccountActivity,currentValue.toString(),Toast.LENGTH_SHORT).show()
}
})
}
XML:
<SeekBar
android:id="@+id/seekbarAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_large"
android:alpha="0.75"
android:max="25"
android:min="7"
android:progress="@{viewModel.fontSize}"
android:progressDrawable="@drawable/progress_seek_bar_settings"
android:splitTrack="false"
android:thumb="@drawable/thumb_seekbar_settins" />