android ProgressBar 的去掉图片白色背景景怎么去掉

8302人阅读
android-Dialog(4)
在自定义组件时,从已有组件源码中会很大收获。
就拿progressDialog来说
& & &间接父类是dialog,想了解dialog继承结构可以去百度,或者
& & 从构造器来说ProgressDialog(Context context, int theme)很明显需要个样式主题文件,我们可以在value文件下自定义一个样式文件。
& &从外观上需要个动态效果控件和文本框两个属性
& & ProgressBar mP & TextView mMessageView
源码中onCreate()方法中 有
& & &View view = inflater.inflate(R.layout.alert_dialog_progress, null);//来加载布局文件
& & &setView(view);
& & 动态效果是由ProgressBar实现,当然我们可以通过给图片添加动态效果也可以实现类似功能,这就需要个anim文件
从上可以总结出创建自定义dialog需要的步骤
&1.继承dialog
&2.一个主题样式文件
&3.一个布局文件来加载
&4.一个anim文件
代码:public class IphoneProgersssDialog extends Dialog {
& &private C
& &private ImageV
& &private TextV
& & & &public IphoneProgersssDialog(Context context) {
& & & & & & & &super(context, R.style.iphone_progress_dialog);
& & & & & & & &this.context=
& & & & & & & &//加载布局文件
& & & & & & & &LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
& & & & & & & &View &view=inflater.inflate(R.layout.iphone_progress_dialog, null);&
& & & & & & & &img=(ImageView) view.findViewById(R.id.iphone_progress_dialog_img);
& & & & & & & &txt=(TextView) view.findViewById(R.id.iphone_progress_dialog_txt);
& & & & & & & &//给图片添加动态效果
& & & & & & & &Animation anim=AnimationUtils.loadAnimation(context, R.anim.progressbar);
& & & & & & & &img.setAnimation(anim);
& & & & & & & &txt.setText(R.string.iphone_progressbar_dialog_txt);
& & & & & & & &//dialog添加视图
& & & & & & & &setContentView(view);
& & & &public void setMsg(String msg){
& & & & & & & &txt.setText(msg);
& & & &public void setMsg(int msgId){
& & & & & & & &txt.setText(msgId);
看了下pregeressdialog中像activity类一样都有生命周期函数,其实dialog和activity都是窗体概念,并不是api中window类,有个地方还是不明白,希望哪位以后版主有针对setcontentview 和setview的话题。
& 现在我们就做个iphone风格的进度条吧!
& & public class IphoneProgersssDialog extends Dialog&
2.定义主题样式&
& &在value资源文件下
& & &style name=&iphone_progress_dialog& parent=&@android:style/Theme.Dialog&&
& & &&item name=&android:windowFrame&&@null&/item& &!--Dialog的windowFrame框为无 --&&
& & &&item name=&android:windowIsFloating&&true&/item&&!-- 是否漂现在activity上--&
& & &&item name=&android:windowIsTranslucent&&true&/item&&!-- 是否半透明 --&
& & &&item name=&android:windowNoTitle&&true&/item&
& & &&item name=&android:backgroundDimEnabled&&false&/item&&!--
dim:模糊的 阴影效果&--&
& & &&item name=&android:windowBackground&&@drawable/load_bg&/item&&!--
背景图片的大小也影响窗口的大小&--&
& &&/style&
在构造器中 & super(context, R.style.iphone_progress_dialog);
3.定义动画文件 &progressbar.xml
& &?xml version=&1.0& encoding=&utf-8&?&
&set xmlns:android=&/apk/res/android&
& &android:shareInterpolator=&false& &
& & & &android:interpolator=&@android:anim/linear_interpolator&
& & & &android:pivotX=&50%&
& & & &android:pivotY=&50%&
& & & &android:fromDegrees=&0&
& & & &android:toDegrees=&+360&
& & & &android:duration=&1000&
& & & &android:startOffset=&-1&
& & & &android:repeatMode=&restart&
& & & &android:repeatCount=&-1&/&
给图片加载动画
Animation anim=AnimationUtils.loadAnimation(context, R.anim.progressbar);
&img.setAnimation(anim);
最后就是setC没有去分析setView的区别
图片不晓得我只上传不了,也许是浏览器的原因吧。
& &使用方法:
& new&IphoneProgersssDialog ().show();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:525683次
积分:5010
积分:5010
排名:第3873名
原创:82篇
转载:127篇
评论:30条
(5)(2)(2)(2)(4)(1)(8)(11)(2)(5)(4)(6)(1)(2)(2)(2)(5)(9)(3)(12)(18)(6)(3)(2)(1)(2)(1)(2)(20)(15)(7)(8)(10)(1)(1)(1)(14)(9)如何改变Android Progressbar默认颜色_百度知道android progressBar小结(可改变背景色)
主要是通过点击按钮,重新给进度条设值
package com.
import android.app.A
import android.os.B
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.ProgressB
import android.widget.TextV
public class MainActivity extends Activity {
private ProgressBar p1;
private TextV
private int flag = 10;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p1 = (ProgressBar) findViewById(R.id.progressBar1);
tv = (TextView) findViewById(R.id.textView1);
btn = (Button) findViewById(R.id.button1);
p1.setMax(100);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
p1.setProgress(flag);
MainActivity.this.tv.setText(flag + "%");
if(flag > 90){
flag = 100;
flag += 10;
给进度条设置背景色
a.b为两个图片,放在drawable中
layout文件
在网上有看到一个自定义的,加到这里跟大家分享。转自:/thread--1.html
一般的ProgressBar都只是一个光光的条(这里说的都是水平进度条),虽然比不用进度条时给用户的感觉要好,但是如果在形像化的东西上面再加上点文字,将进度描述量化,就可以让用户更加明白当前进度是多少了。
  有了需求,就可以开始实现了。
  这里的原理就是继承一个ProgressBar,然后重写里面的onDraw()方法。
  不多说,直接上码。(下面代码中的
package hol. ,import就不写了)
public class MyProgress extends ProgressBar{
public MyProgress(Context context) {
super(context);
// TODO Auto-generated constructor stub
System.out.println("1");
initText();
public MyProgress(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
System.out.println("2");
initText();
public MyProgress(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
System.out.println("3");
initText();
public synchronized void setProgress(int progress) {
// TODO Auto-generated method stub
setText(progress);
super.setProgress(progress);
protected synchronized void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
//this.setText();
Rect rect = new Rect();
this.mPaint.getTextBounds(this.text, 0, this.text.length(), rect);
int x = (getWidth() / 2) - rect.centerX();
int y = (getHeight() / 2) - rect.centerY();
canvas.drawText(this.text, x, y, this.mPaint);
//初始化,画笔
private void initText(){
this.mPaint = new Paint();
this.mPaint.setColor(Color.WHITE);
private void setText(){
setText(this.getProgress());
//设置文字内容
private void setText(int progress){
int i = (progress * 100)/this.getMax();
this.text = String.valueOf(i) + "%";
 这样一个可以满足我们基本需求的进度条就写好了。  用的时候就可以直接在layout的XML里面加了,不过添加的写法稍微有点不同。标记名要写成这个自定义进度条的完整类名,就像下面这样。
这样写后,可能会因为命名空间改变,下面属性无法用代码提示。一个简单的做法就是,先写一个正常的ProgressBar的标记,把属性写完后,再将ProgressBar替换为我们自定义的进度条的完整类名。  最后,使用方法就和普通的ProgressBar差不多了。
public class ProgressTest extends Activity {
private Button btn_go =
private MyProgress myProgress =
private Handler mH
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findView();
setParam();
addListener();
mHandler = new Handler(new Callback() {
public boolean handleMessage(Message msg) {
// TODO Auto-generated method stub
myProgress.setProgress(msg.what);
private void findView(){
btn_go = (Button) findViewById(R.id.btn_go);
myProgress = (MyProgress) findViewById(R.id.pgsBar);
private void setParam(){
btn_go.setText("开始");
private void addListener(){
btn_go.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
for(int i = 0;i <=50; i++){
mHandler.sendEmptyMessage(i * 2);
Thread.sleep(80);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}).start();
PS:刚开始本以为进度条的构造方法只需要重写那个最长参数的,也就是那个构造方法3,实际上我测试的时候基本都是运行的3方法。但有一次出错了,最后才找到系统居然用的1方法,所以没办法,直接把三个构造方法全重写了。如果有谁知道原因,麻烦告诉一下。进度条上的文字信息,不一定非要百分比,可以自由发挥。比如类&#20284;
“当前个数/总数”。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'android progressbar的白色背景怎么去掉_百度知道

我要回帖

更多关于 word白色背景怎么去掉 的文章

 

随机推荐