Android SeekBar can't be full width even set padding 0 in AppCompat 23.1.0

亡梦爱人 提交于 2019-11-30 06:34:00

finally, I just have a sudden thought. why not try modify it by java code. It works! following is the sample code:

protected void initViews(Context context) {
    LayoutInflater.from(context).inflate(getLayoutResId(), this);
    ButterKnife.bind(this);

    // set style, just once
    seekBar.setProgress(0);
    seekBar.setMax(0);

    seekBar.setPadding(0, 0, 0, 0);

    // ...
}
bhoomika

Set this attributes in XML

android:paddingStart="0dp" 
Dídac Corbí Albella

Try adding the parameters paddingStart and paddingEnd to 0dp in the xml file. If your app is compatible with Rtl you will need to add those in order to visualize the seekBar with no padding otherwise it will show with padding even if using it in a Ltr language.

Punnya Cipson

As Didac mentioned you can set the padding to 0 in xml.

But make sure you set the padding after you set the progressTint or progressDrawable.

I had a similar problem (where I was setting progressDrawable). Once I set the padding as 0 after setting the progressDrawable, the seekbar padding has gone

if you seekBar.setPadding(0, 0, 0, 0); may be the thumb can't show complete。 First, you should find what result this. In fact, in the seek bar style, you can find this.

<style name="Base.Widget.AppCompat.SeekBar" parent="android:Widget">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/abc_seekbar_track_material</item>
    <item name="android:indeterminateDrawable">@drawable/abc_seekbar_track_material</item>
    <item name="android:thumb">@drawable/abc_seekbar_thumb_material</item>
    <item name="android:focusable">true</item>
    <item name="android:paddingLeft">16dip</item>
    <item name="android:paddingRight">16dip</item>
</style>

so change the style with paddingLeft and paddingRight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!