Android 6.0 Marshmallow停止显示Vertical SeekBar thumb

我一直在SeekBar周围使用 this basic wrapper,但发现它隐藏了拇指,或者在Marshmallow的白色背景上做了一些像白色一样的时髦.

我使用AS“BlankActivity”向导来创建一个项目来说明这一点,除了认设置之外什么都没有改变.左边是Lollipop,同样的代码在Marshmallow右边运行:

一个自定义水平SeekBar来测试是否存在定制它们的一般问题,但没有.左边的第一个垂直方向没有样式,这在Marshmallow之前很好,但是没有其他方式,中央显式使用Widget.Material.Light.SeekBar样式来测试认情况是否未被拾取,并且最后一个给出了一个很大的线索,因为它使用旧的Widget.Holo.SeekBar样式然后出现,虽然看起来它几年前出现.

这是这个的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    >

    <com.otamate.seekbarmarshbug.CustomSeekBar
        android:id="@+id/seekBarCustom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    <com.otamate.seekbarmarshbug.VerticalSeekBar
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/seekBarCustom"
        />

    <com.otamate.seekbarmarshbug.VerticalSeekBar
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:layout_below="@+id/seekBarCustom"
        android:layout_centerHorizontal="true"
        style="@android:style/Widget.Material.Light.SeekBar"
        />

    <com.otamate.seekbarmarshbug.VerticalSeekBar
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/seekBarCustom"
        style="@android:style/Widget.Holo.SeekBar"
        />

</RelativeLayout>

CustomSeekBar:

package com.otamate.seekbarmarshbug;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class CustomSeekBar extends SeekBar {

    public CustomSeekBar(Context context) {
        super(context);
    }

    public CustomSeekBar(Context context,AttributeSet attrs,int defStyle) {
        super(context,attrs,defStyle);
    }

    public CustomSeekBar(Context context,AttributeSet attrs) {
        super(context,attrs);
    }
}

和VerticalSeekBar:

package com.otamate.seekbarmarshbug;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;

public class VerticalSeekBar extends SeekBar {

    public VerticalSeekBar(Context context) {
        super(context);
    }

    public VerticalSeekBar(Context context,defStyle);
    }

    public VerticalSeekBar(Context context,attrs);
    }

    protected void onSizeChanged(int w,int h,int oldw,int oldh) {
        super.onSizeChanged(h,w,oldh,oldw);
    }

    @Override
    protected synchronized void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {
        super.onMeasure(heightMeasureSpec,widthMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(),getMeasuredWidth());
    }

    protected void onDraw(Canvas c) {
        c.rotate(-90);
        c.translate(-getHeight(),0);

        super.onDraw(c);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!isEnabled()) {
            return false;
        }

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
                setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
                onSizeChanged(getWidth(),getHeight(),0);
                break;

            case MotionEvent.ACTION_CANCEL:
                break;
        }
        return true;
    }

}

解决方法

试试这个代码.它工作正常!
<seekBar>
   .....
   android:splitTrack="false"
</seekBar>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...