Android自定义titlebar中设置progressbar

先上结果图

源代码:http://download.csdn.net/detail/beifengdelei/4113962

代码如下

package com.android.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ProgressBar;

public class MytestActivity extends Activity {
	private ProgressBar LoadProgressBar;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值
        
        LoadProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
        
        Thread thread = new Thread(new Runnable() {
			@Override
			public void run() {
		        	try {
		        		for(int i=1;i<=100;i++){
		        			i =i+10;
				        	LoadProgressBar.setProgress(i);
				        	Thread.sleep(1000);
		        		}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		});
        thread.start();
    }
    
}

title.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
    
    <ProgressBar 
        android:id="@+id/progressBar1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
		style="?android:attr/progressBarStyleHorizontal" 
		android:progressDrawable="@drawable/progressbar_style"
		android:max="100" 
		android:progress="0"
		android:layout_alignTop="@+id/textView1"
></ProgressBar>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="自定义标题栏" />
    

</RelativeLayout>

drawable/progressbar_style.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="5.0dip" />
            <gradient android:startColor="#656666" android:endColor="#dbdedf" android:angle="270.0" android:centerY="0.75" android:centerColor="#bbbbbc" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="8.0dip" />
                <gradient android:startColor="#e71a5e" android:endColor="#6c213a" android:angle="90.0" android:centerY="0.75" android:centerColor="#ac6079" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="8.0dip" />
                <gradient android:startColor="#464647" android:endColor="#2d9ae7" android:angle="270.0" />
            </shape>
        </clip>
    </item>
</layer-list>



你可能感兴趣的:(thread,c,android,layout,Class,encoding)