android seekbar 圆角,android – 删除自定义Seekbar的圆角边缘?
时间: 2024-03-09 18:46:39 浏览: 42
要删除自定义 SeekBar 的圆角边缘,可以通过设置 SeekBar 的背景为一个没有圆角的 Drawable 来实现。具体实现步骤如下:
1. 在 res/drawable 文件夹下创建一个新的 Drawable 文件,例如 seekbar_bg.xml,代码如下:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="0dp" />
<solid android:color="#FF0000" />
</shape>
```
这个 Drawable 代表一个没有圆角的红色矩形。
2. 在布局文件中,将 SeekBar 的 android:background 属性设置为刚才创建的 Drawable,例如:
```
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:min="0"
android:max="100"
android:progress="50"
android:background="@drawable/seekbar_bg" />
```
这样就可以删除自定义 SeekBar 的圆角边缘了。
相关问题
Android SeekBar 属性?
Android SeekBar是一种用户界面控件,用于允许用户在滑动条上以连续方式选择数值。它有以下属性:
1. android:id:为SeekBar指定一个唯一的标识符。
2. android:layout_width和android:layout_height:SeekBar的宽度和高度。
3. android:max:SeekBar的最大值。
4. android:progress:SeekBar的当前进度值。
5. android:thumb:SeekBar的滑块图像。
6. android:thumbOffset:滑块相对于SeekBar轨道的偏移量。
7. android:progressDrawable:SeekBar的进度条图像。
8. android:secondaryProgress:SeekBar的次进度值,用于显示额外的进度条。
9. android:splitTrack:如果为true,则SeekBar的进度条在滑块之前和之后分开。
10. android:padding:SeekBar的轨道和滑块之间的间距。
11. android:background:SeekBar的背景图像。
android 有背景图的seekbar 怎么设置成圆角
如果你想要一个带有背景图的 SeekBar 并设置成圆角,可以通过自定义 Drawable 来实现。具体实现步骤如下:
1. 在 res/drawable 文件夹下创建一个新的 Drawable 文件,例如 seekbar_bg.xml,代码如下:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="#FFFFFF" />
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
```
这个 Drawable 代表一个白色背景,黑色边框,圆角为 20dp 的矩形。
2. 在布局文件中,将 SeekBar 的 android:progressDrawable 和 android:thumb 属性设置为自定义的 Drawable,例如:
```
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:min="0"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/seekbar_thumb" />
```
3. 创建一个新的 Drawable 文件,例如 seekbar_progress.xml,代码如下:
```
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/seekbar_bg" />
<item android:id="@android:id/progress">
<clip>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="#00FF00" />
</shape>
</clip>
</item>
</layer-list>
```
这个 Drawable 代表一个带有背景图的 SeekBar,进度条为绿色,圆角为 20dp。
4. 创建一个新的 Drawable 文件,例如 seekbar_thumb.xml,代码如下:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:width="30dp"
android:height="30dp" />
<solid android:color="#000000" />
</shape>
```
这个 Drawable 代表一个黑色的圆形拇指。
这样就可以实现一个带有背景图的 SeekBar 并设置成圆角了。