【问题标题】:Android Remove SeekBar BackgroundAndroid 移除 SeekBar 背景
【发布时间】:2017-12-21 23:39:53
【问题描述】:

有没有办法可以删除 SeekBar android 小部件中的背景栏图像?

我只是希望它显示一个没有进度条的滑块。

有什么帮助吗?

【问题讨论】:

    标签: java android seekbar


    【解决方案1】:

    有一种更简单的方法,不需要创建新的可绘制对象。 只需在您的 xml 定义中设置以下内容

    android:progressDrawable="@android:color/transparent"
    

    或者如果你想在你的代码中这样做:

    mySlider.setProgressDrawable(new ColorDrawable(android.R.color.transparent));
    

    【讨论】:

    • 比上面@GuyNoir 的解决方案更好的解决方案,后者需要创建一个人工的“不可见的可绘制对象”
    • 请注意:您不能使用#0000,但使用@android:color/transparent 可以。
    • 但这也删除了全息光主题上的水平线。我想保留它。
    • @lalitm 我不确定你的意思。 OP想要删除栏并只保留选项卡。水平线不是相当于全息灯中的条吗?我想最好的办法是发布一个新问题并附上你想做的事情的图片。或者也许下面 CommonsWare 的答案是你想要做的?
    【解决方案2】:

    好吧,我解决了我自己的问题。

    要移除背景,你必须创建一个空白drawable并将其设置为progressDrawable:

    satBar.setProgressDrawable(invisibleBackground);
    

    将其设置为 null 似乎不起作用。

    【讨论】:

      【解决方案3】:

      【讨论】:

      • 我有。背景可绘制对象实际上位于栏本身的后面。我需要一种方法来删除栏(并更改滑块的图像)
      • 那之后我如何恢复到初始状态? tks
      • @Paul:尝试先调用getBackground(),将结果保存在某处,然后通过setBackgroundDrawable() 恢复它。尽管名称不平行,getBackground() 返回 Drawable
      • 不幸的是没有工作...我在这里发布了一个与此问题相关的明确问题:stackoverflow.com/questions/14054548/… 谢谢。
      【解决方案4】:

      一种方法是将进度条的颜色更改为背景颜色。您必须使用自定义布局。

      <SeekBar
        android:layout_width="350px"
        android:layout_height="25px"
        android:layout_margin="30px"
        android:layout_x="60px"
        android:layout_y="185px"
        android:id="@+id/seekbar"
        android:progressDrawable="@drawable/myprogress"
      />
      

      下面给出了一个自定义布局 - 玩弄颜色:

      <?xml version="1.0" encoding="utf-8"?>
      <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      
      <item android:id="@android:id/background">
      <shape>
          <corners android:radius="5dip" />
          <gradient
                  android:startColor="#ff9d9e9d"
                  android:centerColor="#ff5a5d5a"
                  android:centerY="0.75"
                  android:endColor="#ff747674"
                  android:angle="270"
          />
      </shape>
      </item>
      
      
      <item
      android:id="@android:id/progress"
      >
      <clip>
          <shape>
              <corners
                  android:radius="5dip" />
              <gradient
                  android:startColor="#9191FE"
                  android:centerColor="#9191FE"
                  android:centerY="0.75"
                  android:endColor="#9191FE"
                  android:angle="270" />
          </shape>
      </clip>
      </item>
      

      【讨论】:

        【解决方案5】:

        创建一个xml文件seekbar_progress.xml并将其放在drawable文件夹中。这里stripes是一个图像,取一个图像并将它放在drawable文件夹中。

        seekbar_progress.xml

        <?xml version="1.0" encoding="utf-8"?>
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
        
          <item>
            <clip>
            <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
                android:src="@drawable/stripes"
                android:tileMode="repeat"
                android:antialias="true"
                android:dither="true"
                android:filter="false"
                android:gravity="left"
            />
            </clip>
        </item>
        </layer-list>
        

        现在在您的main xml 文件中,该文件包含搜索条码,拍摄一张图片并存储在drawable 文件夹中。这里的搜索条是一张图片。

            <SeekBar
                     android:id="@+id/seekbar"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:background="@drawable/seekbar"
                     android:progressDrawable="@drawable/seekbar_progress"/>
        

        【讨论】:

          猜你喜欢
          • 2016-01-27
          • 2020-09-28
          • 1970-01-01
          • 2021-12-01
          • 1970-01-01
          • 2019-04-10
          • 2021-06-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多