如何制作这样的搜索栏

时间:2013-05-09 14:11:34

标签: android styles seekbar

我想将效果应用于搜索栏,如下所示:

Download it...

horizontal progress Image

我尝试的内容如下所示。完整的代码在下面只是尝试告诉我你是否会得到如下效果。

MainActivity.java

public class MainActivity extends Activity 
{

 private static int myProgress=0;
 private SeekBar seekBar;
 private int progressStatus=0;
 private Handler myHandler=new Handler();

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.h_processbar);

}

public void beginYourTask(View view)
{

    myProgress=0;
    seekBar= (SeekBar)findViewById(R.id.seekBar);
    seekBar.setMax(100);

    new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            while(progressStatus<100)
            {
                progressStatus=performTask();
                myHandler.post(new Runnable()
                {
                public void run() {
                seekBar.setProgress(progressStatus);
                }
                });

            }
            myHandler.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                   Toast.makeText(getBaseContext(),"Task Completed",Toast.LENGTH_LONG).show();
                   progressStatus=0; 
                   myProgress=0;

                }
            });

        }
        private int performTask()
        {
            try {
                //---Do some task---
                Thread.sleep(100);
                } catch (InterruptedException e)
                {
                e.printStackTrace();
                }
                return ++myProgress;    
        }
    }).start();
   }

 }

progress_horizo​​ntal_green.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">
    <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="#ff54e854"
                    android:centerColor="#ff004900"

                    android:endColor="#ff54e854"
                    android:angle="90"
            />
        </shape>
    </clip>
 </item>

 </layer-list>

h_processbar.xml

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="beginYourTask"
    android:text="Start Task" 
    android:textColor="#ffffff"
    android:layout_margin="10dp"/>
 <LinearLayout 
   android:layout_width="290dp"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:layout_marginTop="30dp"
   >

        <SeekBar
            android:id="@+id/seekBar"
            android:max="100" 
            android:progress="60"
            android:layout_width="260dp"
            android:layout_height="wrap_content"
            android:thumb="@drawable/down_arrow_new"
            android:progressDrawable="@drawable/progress_horizontal_green"
            android:layout_margin="20dp"
            />

</LinearLayout>

down_arrow_new.png 在这里horizontal progress Image Download it...

如图 LHS (左手边)所示,它从深绿色开始 ,随着进度的推进,它看起来像浅绿色阴影的组合 模糊效果。

模糊效果让这真棒。

我怎样才能做到这一点?有什么想法吗?

任何帮助将不胜感激。

谢谢。

0 个答案:

没有答案