删除自定义搜索栏的圆边?自定义

2023-09-13 01:31:55 作者:自卑

我想自定义搜索栏。我有这样的大多是工作,但我无法删除该搜索栏的圆边。我知道有这方面的许多问题,并运用角落0dp会有帮助,但我不知道在哪里可以实现这个形状。当我尝试显示的形状,它越来越尖锐的边缘,但我的背景没有显示,它显示一个黑色的长方形。我想和我的背景锋利的边缘。

seekbarprogrss.xml

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <项目机器人:ID =@机器人:ID /背景>
        <位图
            的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:TILEMODE =回头客
            机器人:反锯齿=真
            机器人:抖动=假
            机器人:过滤器=假
            机器人:重力=左
            机器人:SRC =@可绘制/ cover_back/>
    < /项目>
    <项目
        机器人:ID =@机器人:ID /进步
        机器人:可绘制=@可绘制/ seek_progress_bg/>

< /层列表>
 

seek_progress_bg.xml

 < XML版本=1.0编码=UTF-8&GT?;
 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <项目>
        <夹>
        <位图的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            机器人:SRC =@可绘制/ cover_front
            机器人:TILEMODE =回头客
            机器人:反锯齿=真
            机器人:抖动=假
            机器人:过滤器=假
            机器人:重力=左
        />
        < /剪辑>
    < /项目>

< /层列表>
 

搜索栏落实

 <搜索栏
        机器人:ID =@ + ID / seekBar1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID /按钮2
        机器人:进度=0
        机器人:secondaryProgress =0
        机器人:填充=0dp
        机器人:thumbOffset =0dp
        机器人:progressDrawable =@可绘制/ seekbarprogrss
        机器人:拇指=@可绘制/覆盖
 
PPT2016自定义快速访问工具栏的删除

解决方案

搜索栏自定义的

首先,创建一个自定义类的 mSeekbar.java

 公共类mSeekbar扩展搜索栏{
    公共搜索栏(上下文的背景下){
        超(上下文);
        初始化();
    }
    公共搜索栏(上下文的背景下,ATTRS的AttributeSet){
        超(背景下,ATTRS);
        初始化();
    }
    公共搜索栏(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
        超(背景下,ATTRS,defStyle);
        初始化();
    }
    私人无效初始化(){
       this.setBackgroundDrawable(getResources()getDrawable(R.drawable.shape));
       this.setProgressDrawable(getResources()getDrawable(R.drawable.seek_bar_base));
    }
}
 

那么,这部分添加到您的XML

 <软件包名.seekBar
        机器人:ID =@ + ID /搜索栏
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:拇指=@可绘制/ red_front
        机器人:填充=0dp
        机器人:进度=0
        机器人:不确定=假
        机器人:secondaryProgress =0
        机器人:thumbOffset =0dp/>
 

使用这些可绘制的

seek_bar_base.xml

 <层列表
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目
        机器人:ID =@机器人:ID /背景>
        <位图
            机器人:SRC =@可绘制/ gray_back
            机器人:TILEMODE =重复>
        < /位图>
    < /项目>
    <项目
        机器人:ID =@机器人:ID /进步>
        <层列表
            的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
            <项目>
                <夹>
                    <位图
                        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                        机器人:SRC =@可绘制/ gray_front
                        机器人:TILEMODE =重复/>
                < /剪辑>
            < /项目>
        < /层列表>
    < /项目>
< /层列表>
 

shape.xml

 <形状
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <边角机器人:半径=0dp/>
    < /形状>
 

图片使用

gray_back.jpg

gray_front.jpg

red_front.jpg

I'm trying to customize a seekbar. I have this mostly working, but I am not able to remove the rounded edges of this seekbar. I know there are many questions regarding this, and that applying corners 0dp will help, but I don't know where to implement this shape. When I try to display the shape, it's getting sharp edges but my background is not showing, it's showing a black rectangular shape. I want to have sharp edges with my background.

seekbarprogrss.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/background">
        <bitmap
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
            android:src="@drawable/cover_back" />
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/seek_progress_bg"/>

</layer-list>

seek_progress_bg.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/cover_front"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
        />
        </clip>
    </item>

</layer-list>

Seekbar implementation

 <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button2"
        android:progress="0"
        android:secondaryProgress="0"
        android:padding="0dp"
        android:thumbOffset="0dp"
        android:progressDrawable="@drawable/seekbarprogrss"
        android:thumb="@drawable/cover"

解决方案

SeekBar Customization

First You Create a Custom Class For mSeekbar.java

public class mSeekbar extends SeekBar{
    public seekBar (Context context) {
        super(context);
        Initialise();
    }
    public seekBar (Context context, AttributeSet attrs) {
        super(context, attrs);
        Initialise();
    }
    public seekBar (Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        Initialise();
    }
    private void Initialise(){
       this.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape));
       this.setProgressDrawable(getResources().getDrawable(R.drawable.seek_bar_base));
    }
}

then, add this part to your xml

<"packageName".seekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:thumb="@drawable/red_front"
        android:padding="0dp"
        android:progress="0"
        android:indeterminate="false"
        android:secondaryProgress="0"
        android:thumbOffset="0dp"/>

Use these Drawables

seek_bar_base.xml

<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:id="@android:id/background">
        <bitmap 
            android:src="@drawable/gray_back"
            android:tileMode="repeat">
        </bitmap>
    </item>
    <item 
        android:id="@android:id/progress">
        <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/gray_front"
                        android:tileMode="repeat"/>
                </clip>
            </item>
        </layer-list>
    </item>
</layer-list>

shape.xml

 <shape 
        xmlns:android="http://schemas.android.com/apk/res/android" >
        <corners android:radius="0dp"/>
    </shape>

Images used,

gray_back.jpg

gray_front.jpg

red_front.jpg