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

前端 未结 5 941
天涯浪人
天涯浪人 2020-12-29 20:24

when I update android support lib from 23.0.1 to 23.1.0, I find the SeekBar is not full width any more.

this is the test XML file:



        
相关标签:
5条回答
  • 2020-12-29 21:09

    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.

    0 讨论(0)
  • 2020-12-29 21:10

    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

    0 讨论(0)
  • 2020-12-29 21:22

    Set this attributes in XML

    android:paddingStart="0dp" 
    
    0 讨论(0)
  • 2020-12-29 21:23

    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);
    
        // ...
    }
    
    0 讨论(0)
  • 2020-12-29 21:24

    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

    0 讨论(0)
提交回复
热议问题