更改默认搜索栏的颜色颜色

2023-09-05 23:44:37 作者:`陌然℡

如果有人知道我在做什么错了,请让我知道。 我创建了一个Android应用程序,我试图改变由黄搜索栏的默认颜色为任何其他颜色。我创建了位于所有3可绘制一个XML文件,并运行该项目,但搜索栏的颜色仍然心不是变色。 下面是code我做起,从IRC老乡的队友一直在努力。

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

<项目机器人:ID =@机器人:ID /背景>
    <形状>
        <边角机器人:半径=5dip/>
        <梯度
                机器人:startColor =#ff9d9e9d
                机器人:centerColor =#ff5a5d5a
                机器人:centerY =0.75
                机器人:endColor =#ff747674
                机器人:角=270
        />
    < /形状>
< /项目>

<项目机器人:ID =@机器人:ID / secondaryProgress>
    <夹>
        <形状>
            <边角机器人:半径=5dip/>
            <梯度
                    机器人:startColor =#80ffd300
                    机器人:centerColor =#80ffb600
                    机器人:centerY =0.75
                    机器人:endColor =#a0ffcb00
                    机器人:角=270
            />
        < /形状>
    < /剪辑>
< /项目>
<项目
    机器人:ID =@机器人:ID /进步
>
    <夹>
        <形状>
            <角落
                机器人:半径=5dip/>
            <梯度
                机器人:startColor =#FF0000
                机器人:centerColor =#FF0000
                机器人:centerY =0.75
                机器人:endColor =#FF0000
                机器人:角=270/>
        < /形状>
    < /剪辑>
< /项目>

< /层列表>
 

这是我的Java code

 搜索栏搜索栏=(搜索栏)findViewById(R.id.seekbar);
        最后的TextView seekBarValue =(TextView中)findViewById(R.id.seekbarvalue); //填充搜索栏
        seekBar.setOnSeekBarChangeListener(新SeekBar.OnSeekBarChangeListener()
        {
            @覆盖
            公共无效onProgressChanged(搜索栏搜索栏,INT进步,布尔FROMUSER)
            {

                seekBarValue.setText(将String.valueOf(进度+ 1998)); //设置日期搜索栏在运动的时候
            }
            @覆盖
            公共无效onStartTrackingTouch(搜索栏搜索栏)
            {
                //做自动生成方法存根
            }
            @覆盖
            公共无效onStopTrackingTouch(搜索栏搜索栏)
            {
                //做自动生成方法存根
            }
 
Win7更改任务栏颜色的方法

解决方案

好了,所以基本上所有我需要做的就是进入我的main.xml文件中没有一个设在可绘制文件夹,然后确保把

 安卓progressDrawable =@可绘制/ myprogress
 

在这里myprogress是一个位于可绘制文件夹我的.xml文件的名称。

If anybody knows what i'm doing wrong please let me know. I created an android app and I am trying to change the default color of the seekbar from yellow to any other color. I created an xml file located in all 3 drawables and ran the project but the color of the seekbar still isnt changing color. Below is the code me and a fellow mate from irc have been working on.

    <?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/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>
<item
    android:id="@android:id/progress"
>
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#FF0000"
                android:centerColor="#FF0000"
                android:centerY="0.75"
                android:endColor="#FF0000"
                android:angle="270" />
        </shape>
    </clip>
</item>

</layer-list>

This is my java code

SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);
        final TextView seekBarValue = (TextView) findViewById(R.id.seekbarvalue);       //filling seekbar 
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
        {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
            {

                seekBarValue.setText(String.valueOf(progress+1998));  //sets the date to seekBar when in motion
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar)
            {
                //TO DO Auto-Generated Method stub  
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar)
            {
                //TO DO Auto-Generated Method stub
            }

解决方案

Okay so basically all i needed to do is go into my main.xml file not the one located in the drawables folder and then make sure to put

android:progressDrawable="@drawable/myprogress"

where myprogress is the name of my .xml file located in the drawables folder.