在Android 6.0棉花糖停止显示垂直搜索栏拇指 [英] Android 6.0 Marshmallow stops showing Vertical SeekBar thumb

查看:694
本文介绍了在Android 6.0棉花糖停止显示垂直搜索栏拇指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这个基本的包装围绕一个搜索栏,但发现它隐藏了拇指,或做一些事情一样时髦让白在白色背景上,棉花糖下。

我使用了ASBlankActivity向导创建一个项目来说明这一点,变着法子除了这里描述是什么,从默认值。左边是棒棒糖,同样code是根据棉花糖权运行的:

在这里输入的形象描述

有一个自定义的水平搜索栏,以测试是否有一个普遍的问题定制他们,这不存在。在左侧的第一垂直一只没有风格,这是细$ P $对 - 棉花糖但不另外,中央一显式使用Widget.Material.Light.SeekBar样式来测试如果默认某种程度上没有被拾起和最后一个给出了一个重大线索,因为它使用旧的Widget.Holo.SeekBar风格的地方它会出现,尽管看起来像它在几年前就出来了。

下面是这个布局:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    工具:上下文=。MainActivity
    >    < com.otamate.seekbarmarshbug.CustomSeekBar
        机器人:ID =@ + ID / seekBarCustom
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        />    < com.otamate.seekbarmarshbug.VerticalSeekBar
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent
        机器人:layout_below =@ + ID / seekBarCustom
        />    < com.otamate.seekbarmarshbug.VerticalSeekBar
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent
        机器人:重力=CENTER_HORIZONTAL
        机器人:layout_below =@ + ID / seekBarCustom
        机器人:layout_centerHorizo​​ntal =真
        风格=@安卓风格/ Widget.Material.Light.SeekBar
        />    < com.otamate.seekbarmarshbug.VerticalSeekBar
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent
        机器人:layout_alignParentRight =真
        机器人:layout_below =@ + ID / seekBarCustom
        风格=@安卓风格/ Widget.Holo.SeekBar
        />< / RelativeLayout的>

该CustomSeekBar:

 包com.otamate.seekbarmarshbug;进口android.content.Context;
进口android.util.AttributeSet;
进口android.widget.SeekBar;公共类CustomSeekBar扩展搜索栏{    公共CustomSeekBar(上下文的背景下){
        超级(上下文);
    }    公共CustomSeekBar(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
    }    公共CustomSeekBar(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
    }
}

和VerticalSeekBar:

 包com.otamate.seekbarmarshbug;进口android.content.Context;
进口android.graphics.Canvas;
进口android.util.AttributeSet;
进口android.view.MotionEvent;
进口android.widget.SeekBar;公共类VerticalSeekBar扩展搜索栏{    公共VerticalSeekBar(上下文的背景下){
        超级(上下文);
    }    公共VerticalSeekBar(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
    }    公共VerticalSeekBar(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
    }    保护无效onSizeChanged(INT W,INT小时,INT oldw,诠释oldh){
        super.onSizeChanged(H,W,oldh,oldw);
    }    @覆盖
    保护同步无效onMeasure(INT widthMeasureSpec,诠释heightMeasureSpec){
        super.onMeasure(heightMeasureSpec,widthMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(),getMeasuredWidth());
    }    保护无效的onDraw(帆布C){
        c.ro​​tate(-90);
        c.translate(-getHeight(),0);        super.onDraw(C);
    }    @覆盖
    公共布尔onTouchEvent(MotionEvent事件){
        如果(!isEnabled()){
            返回false;
        }        开关(event.getAction()){
            案例MotionEvent.ACTION_DOWN:
            案例MotionEvent.ACTION_MOVE:
            案例MotionEvent.ACTION_UP:
                setProgress(GetMax的() - (int)的(GetMax的()* event.getY()/的getHeight()));
                onSizeChanged(的getWidth(),的getHeight(),0,0);
                打破;            案例MotionEvent.ACTION_CANCEL:
                打破;
        }
        返回true;
    }}


解决方案

只需使用普通的搜索栏,并采用Android:旋转=270,帮助我

 <搜索栏
机器人:ID =@ + ID /搜索栏
机器人:旋转=270
/>

I've been using this basic wrapper around a SeekBar but find it hides the thumb, or does something funky like make it white on a white background, under Marshmallow.

I used the AS "BlankActivity" wizard to create a project to illustrate this, changing nothing except what is described here, from the defaults. On the left is Lollipop, and the same code is running on the right under Marshmallow:

There is a custom horizontal SeekBar to test if there was a general problem customizing them, which there isn't. The first vertical one on the left has no style, which is fine pre-Marshmallow but not otherwise, the central one explicity uses the Widget.Material.Light.SeekBar style to test if the default somehow wasn't being picked up, and the last one gives a big clue because it uses the old Widget.Holo.SeekBar style where it then appears, albeit looking like it came out a few years ago.

Here's the layout for this:

<?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>

The 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);
    }
}

and the 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, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public VerticalSeekBar(Context context, AttributeSet attrs) {
        super(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, 0);
                break;

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

}

解决方案

Just use a normal SeekBar and use android:rotation="270" that helped for me.

<SeekBar
android:id="@+id/seekBar"
android:rotation="270"
/>

这篇关于在Android 6.0棉花糖停止显示垂直搜索栏拇指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆