导航:首页 > 操作系统 > android自定义进度条图片

android自定义进度条图片

发布时间:2022-09-26 13:43:09

android自定义环形进度条怎么自由控制进度条的消失与隐藏

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetoothmeter);
mhandler = new Handler();

//通过mSearcheHandler更新UI
mSearchHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0){
//改变环形进度条的进度
mCircleProcessBar.setProgress(mcnt);
mcnt+=1;
if(MCNT_MAX<=mcnt){
mCircleProcessBar.setVisibility(View.GONE);
}
}
}
};
mBlueService = BluetoothLeService.getInstance();
initView();
initEvent();
}

private void initEvent()
{
mImgBtnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//搜索
mbtnSearch.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// Prepare list view and initiate scanning
if (m_devicelistadapter != null) {
m_devicelistadapter.clear();
m_devicelistadapter.notifyDataSetChanged();

}
startScan();

//设置圆环进度条的出现时间(秒)
new TimerDelay(mSearchHandler).setDelayTime(CIRCLE_APPARE_TIME,mCircleProcessBar);
mcnt=1;
}
});
}

❷ 关于Android怎么改变ProgressBar进度条颜色

需求:下载中的颜色要自定义,要替换为另外的一个颜色

方法:就是在

<ProgressBar
android:layout_weight="1"
android:id="@+id/download_item_progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="15dip"
android:progressDrawable="@drawable/progressbar_style"></ProgressBar>

在drawable中新建一个progressBar_style.xml文件,

这个属性进行设置,有两个方案:

第一,设置两张图片:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">

<item android:id="@android:id/background"
android:drawable="@drawable/progressbar_not" />

<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/progressbar_not">
</item>

<item android:id="@android:id/progress"
android:drawable="@drawable/progressbar_selected">

</item>
</layer-list>

第二种,设置背景颜色:

<?xml version="1.0" encoding="utf-8"?>
<item android:id="@android:id/background"

>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#666666"

android:centerColor="#666666"

android:centerY="0.75"

android:endColor="#666666"

android:angle="270"

/>

</shape>

</item>

<item android:id="@android:id/progress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#da1f3e"

android:centerColor="#da1f3e"

android:centerY="0.75"

android:endColor="#da1f3e"

android:angle="270"

/>

</shape>

</clip>

</item>

<item android:id="@android:id/secondaryProgress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#fed7ec"

android:centerColor="#fed7ec"

android:centerY="0.75"

android:endColor="#fed7ec"

android:angle="270"

/>

</shape>

</clip>

</item>

</layer-list>

其中的属性还要进一步研究具体作用,据文档翻译有设置角度,渐变的。
转载,仅供参考。

❸ android布局文件里的ProgressBar长形进度条怎么自定义样式

在windows操作系统下Android studio按照如下步骤自动义ProgressBar长形进度条的样式。

1、首先创建一个android项目,打开其中的XML布局文件,如下图:

❹ Android开发怎么自定义绘制如下图中这种进度条急需!在线等!

一)变换前背景

先来看看progressbar的属性:
1. <ProgressBar
2. android:id="@+id/progressBar"
3. style="?android:attr/progressBarStyleHorizontal"
4. android:layout_width="match_parent"
5. android:layout_height="wrap_content"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:indeterminate="false"
9. android:padding="2dip"
10. android:progress="50" />
根据style="?android:attr/progressBarStyleHorizontal",我们找到源码中的style.xml
1. <style name="Widget.ProgressBar.Horizontal">
2. <item name="android:indeterminateOnly">false</item>
3. <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
4. <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
5. <item name="android:minHeight">20dip</item>
6. <item name="android:maxHeight">20dip</item>
7. </style>
看到
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
木有,继续发掘源码,找到drawable下面的progress_horizontal.xml,这就是我们今天的主角了:
1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item android:id="@android:id/background">
4. <shape>
5. <corners android:radius="5dip" />
6. <gradient
7. android:startColor="#ff9d9e9d"
8. android:centerColor="#ff5a5d5a"
9. android:centerY="0.75"
10. android:endColor="#ff747674"
11. android:angle="270"
12. />
13. </shape>
14. </item>
15.
16. <item android:id="@android:id/secondaryProgress">
17. <clip>
18. <shape>
19. <corners android:radius="5dip" />
20. <gradient
21. android:startColor="#80ffd300"
22. android:centerColor="#80ffb600"
23. android:centerY="0.75"
24. android:endColor="#a0ffcb00"
25. android:angle="270"
26. />
27. </shape>
28. </clip>
29. </item>
30.
31. <item android:id="@android:id/progress">
32. <clip>
33. <shape>
34. <corners android:radius="5dip" />
35. <gradient
36. android:startColor="#ffffd300"
37. android:centerColor="#ffffb600"
38. android:centerY="0.75"
39. android:endColor="#ffffcb00"
40. android:angle="270"
41. />
42. </shape>
43. </clip>
44. </item>
45.
46. </layer-list>
看到android:id="@android:id/progress"木有,看到android:id="@android:id/secondaryProgress"木有
把这个文件复制到自己工程下的drawable,就可以随心所欲的修改shape的属性,渐变,圆角等等
那么怎么放一个图片进去呢,ok,新建progress_horizontal1.xml:
1. <?xml version="1.0" encoding="utf-8"?>
2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3.
4. <item android:id="@android:id/progress" android:drawable="@drawable/progressbar" />
5.
6. </layer-list>
在android:drawable中指定你处理好的图片
然后回到布局中
1. <ProgressBar
2. android:id="@+id/progressBar1"
3. android:layout_width="match_parent"
4. android:layout_height="wrap_content"
5. android:layout_below="@+id/progressBar"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:background="@drawable/progress_bg"
9. android:indeterminate="false"
10. android:indeterminateOnly="false"
11. android:maxHeight="20dip"
12. android:minHeight="20dip"
13. android:padding="2dip"
14. android:progress="50"
15. android:progressDrawable="@drawable/progress_horizontal1" />
android:background="@drawable/progress_bg"指定背景
android:progressDrawable="@drawable/progress_horizontal1"前景使用上面的progress_horizontal1

要是还不行

你来我们群里说吧

这里是开发者互相学习交流的 有大神

让他们给你解释你的疑问 号 码look at my n a m e.....

❺ 长按如何使进度条变化Android

通过MediaPlayer调节。
系统自带的进度条的颜色比较单调,实际开发中使用较少,可以自定义进度条背景,新建一个progressbarbg.xml文件。gradient可以设置进度条的渐变色,android:endColor和android:startColor可以设置渐变开始和结束的颜色。定义完成以后,便可以使用。
在音乐进度,网络下载时,需动态加载进度条,默认情况下,设置进度条,使用setProgress即可。但有时除了动态设置进度,仍需要动态设置进度条颜色通过MediaPlayer播放音乐并获取进度,设置进度。

❻ android自定义progressbar图片大小自适应

通过animation-list 动画自定义的progressbar样式,如果progressbar设置的长度和宽度超过了动画中图片的大小,效果会很难看,通过如下方式可解决。 <animation-list xmlns:android="

❼ 自定义progressdialog怎么setmessage

Android SDK已经提供有进度条组件ProgressDialog组件,但用的时候我们会发现可能风格与我们应用的整体风格不太搭配,而且ProgressDialog的可定制行也不太强,这时就需要我们自定义实现一个ProgressDialog。
通过看源码我们发现,ProgressDialog继承自Alertdialog,有一个ProgressBar和两个TextView组成的,通过对ProgressDialog的源码进行改进就可以实现一个自定义的ProgressDialog。

1、效果:

首先看一下自定义CommonProgressDialog和原生ProgressDialog的对比:


2、代码:

common_progress_dialog.xml 布局文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="798px"
android:layout_height="460px"
android:orientation="vertical"
android:background="@drawable/common_progress_dialog_background">
<TextView
android:id="@+id/progress_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="44px"
android:layout_marginTop="113px"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="712px"
android:layout_height="30px"
android:layout_marginTop="100px"
android:layout_marginLeft="47px"
android:layout_centerHorizontal="true"
android:progressDrawable="@drawable/common_progressdialog_progressbar_background"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/progress_percent"
android:layout_width="80px"
android:layout_height="wrap_content"
android:textSize="30px"
android:layout_marginLeft="280px"
android:gravity="center_horizontal"
android:textColor="#ffffff"
/>
<TextView
android:id="@+id/progress_number"
android:layout_width="250px"
android:layout_height="wrap_content"
android:layout_marginLeft="120px"
android:textSize="30px"
android:gravity="center_horizontal"
android:textColor="#ffffff"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>

common_progressdialog_progressbar_background.xml Progressbar进度条图片和背景图片设置

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@android:id/background"
android:drawable="@drawable/common_progress_dialog_progressbar3"
/>
<item
android:id="@android:id/progress"
android:drawable="@drawable/common_progress_dialog_progressbar2"
/>

</layer-list>

CommonProgressDialog.java类:

package com.johnny.testactivity;


import java.text.NumberFormat;


import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;


public class CommonProgressDialog extends AlertDialog {


private ProgressBar mProgress;
private TextView mProgressNumber;
private TextView mProgressPercent;
private TextView mProgressMessage;

private Handler mViewUpdateHandler;
private int mMax;
private CharSequence mMessage;
private boolean mHasStarted;
private int mProgressVal;

private String TAG="CommonProgressDialog";
private String mProgressNumberFormat;
private NumberFormat mProgressPercentFormat;
public CommonProgressDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
initFormats();
}


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.common_progress_dialog);
mProgress=(ProgressBar) findViewById(R.id.progress);
mProgressNumber=(TextView) findViewById(R.id.progress_number);
mProgressPercent=(TextView) findViewById(R.id.progress_percent);
mProgressMessage=(TextView) findViewById(R.id.progress_message);
// LayoutInflater inflater = LayoutInflater.from(getContext());
mViewUpdateHandler = new Handler() {


@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
int progress = mProgress.getProgress();
int max = mProgress.getMax();
double dProgress = (double)progress/(double)(1024 * 1024);
double dMax = (double)max/(double)(1024 * 1024);
if (mProgressNumberFormat != null) {
String format = mProgressNumberFormat;
mProgressNumber.setText(String.format(format, dProgress, dMax));
} else {
mProgressNumber.setText("");
}
if (mProgressPercentFormat != null) {
double percent = (double) progress / (double) max;
SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mProgressPercent.setText(tmp);
} else {
mProgressPercent.setText("");
}
}

};
// View view = inflater.inflate(R.layout.common_progress_dialog, null);
// mProgress = (ProgressBar) view.findViewById(R.id.progress);
// mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
// mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
// setView(view);
//mProgress.setMax(100);
onProgressChanged();
if (mMessage != null) {
setMessage(mMessage);
}
if (mMax > 0) {
setMax(mMax);
}
if (mProgressVal > 0) {
setProgress(mProgressVal);
}
}
private void initFormats() {
mProgressNumberFormat = "%1.2fM/%2.2fM";
mProgressPercentFormat = NumberFormat.getPercentInstance();
mProgressPercentFormat.setMaximumFractionDigits(0);
}
private void onProgressChanged() {
mViewUpdateHandler.sendEmptyMessage(0);


}
public void setProgressStyle(int style) {
//mProgressStyle = style;
}
public int getMax() {
if (mProgress != null) {
return mProgress.getMax();
}
return mMax;
}
public void setMax(int max) {
if (mProgress != null) {
mProgress.setMax(max);
onProgressChanged();
} else {
mMax = max;
}
}
public void setIndeterminate(boolean indeterminate) {
if (mProgress != null) {
mProgress.setIndeterminate(indeterminate);
}
// else {
// mIndeterminate = indeterminate;
// }
}
public void setProgress(int value) {
if (mHasStarted) {
mProgress.setProgress(value);
onProgressChanged();
} else {
mProgressVal = value;
}
}


@Override
public void setMessage(CharSequence message) {
// TODO Auto-generated method stub
//super.setMessage(message);
if(mProgressMessage!=null){
mProgressMessage.setText(message);
}
else{
mMessage = message;
}
}


@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mHasStarted = true;
}


@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
mHasStarted = false;
}

}

测试程序:

private void showDialog(){
mDialog = new CommonProgressDialog(this);

mDialog.setMessage("正在下载");
mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mDialog.setOnCancelListener(new OnCancelListener() {

@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
//cancel(true);
}
});
mDialog.show();

mDialog.setMax(100*1024*1024);
mDialog.setProgress(65*1024*1024);
}

❽ android 怎么自定义绘制如下图中这种进度条

下面是安卓学习手册中实现各种进度条的截图:

要想看各种进度条的实现代码和文档,直接去360手机助手中下载安卓学习手册,例子文档随便看。

1、说明

在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。一个进度条也可不确定其进度。在不确定模式下,进度条显示循环动画。这种模式常用于应用程序使用任务的长度是未知的。

2、XML重要属性

android:progressBarStyle:默认进度条样式

android:progressBarStyleHorizontal:水平样式

3 重要方法

getMax():返回这个进度条的范围的上限

getProgress():返回进度

getSecondaryProgress():返回次要进度

incrementProgressBy(int diff):指定增加的进度

isIndeterminate():指示进度条是否在不确定模式下

setIndeterminate(boolean indeterminate):设置不确定模式下

setVisibility(int v):设置该进度条是否可视

4 重要事件

onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件

5进度条的样式

Widget.ProgressBar.Horizontal长形进度

Androidxml 布局:

<ProgressBar

android:id="@+id/progress_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

style="@android:style/Widget.ProgressBar.Horizontal "

/>

源码:

private ProgressBar mProgress;

private int mProgressStatus=0;

private Handler mHandler=newHandler();

@Override

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mProgress=(ProgressBar)findViewById(R.id.progress_bar);

new Thread(new Runnable(){

@Override

public void run(){

while(mProgressStatus<100){

mProgressStatus=doWork();

mHandler.post(new Runnable(){

@Override

public void run(){

mProgress.setProgress(mProgressStatus);

}

});

}

}

}).start();

}

效果图:

带第二进度的进度条

xml配置如下:

<ProgressBar

android:id="@+id/progress_bar_with_second"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="40"

android:secondaryProgress="70"

android:paddingTop="20dp"

android:paddingBottom="20dp"/>

这里我们设置了初始的进度为40,android:progress的值在mini和max之间即mini<=progressvalue<=max

设置了第二进度条的进度值为70,该值也在mini和max之间。

效果如下:

不确定模式进度条

xml配置文件:

<ProgressBar

android:id="@+id/progress_bar_indeterminate"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:indeterminate="true"

android:indeterminateBehavior="cycle"

android:paddingBottom="20dp"

android:paddingTop="20dp"

android:progress="40" />

这里通过android:indeterminate="true"设置了当前为无模式进度条

效果如图:

普通圆形进度:Widget.ProgressBar.Inverse

<ProgressBar

android:id="@+id/progress_bar1"

style="@android:style/Widget.ProgressBar.Inverse"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="50"

android:background="#ff00ff"

android:paddingTop="4dp" />

通过android:backgroup设置了背景色

❾ Android自定义RatingBar(星级评分控件)

RatingBar是基于SeekBar(拖动条)和ProgressBar(状态条)的扩展,用星形来显示等级评定!

RatingBar实现的效果图:

      看着自定义的样式远远比Android自带的样式好看多了,用户体验度远远提升,下面我们就来实现该控件:

  定义根据图片自定一个RatingBar的背景条,和图片放到同一个目录下面

     five_rating_bar.xml

backgroud:是用来填充背景图片的,和进度条非常类似,当我们设置最高评分时(android:numStars),系统就会根据我们的设置,来画出以星星为单位的背景(假如android:numStars="5",就会画出5颗灰色的星星)

progress:是用来在背景图片基础上进行填充的指示属性(和进度条类似,第一进度位置)

secondaryProgress:同progress一样属于第二进度位置(如果不定义这个,进度条拖动,每次就画出一整颗星星(亮),第二进度(暗)没有覆盖掉第一进度之后的位置,从左往右是拖不出来N.5颗星星的,这样评分效果就不完整)

    style.xml

      提取样式属于个人习惯,这里可以不提取出来,可以写在布局文件中,这里RatingBar的样式是通过style来切换的。

    通过 parent属性来选择继承的父类,我们这里继承RatingBar类。

    重新定义 progressDrawable属性(RatingBar的背景条)

    maxHeight和minHeight可以根据我们图片像素或者其他参考值来设定。

在我们需要用到RatingBar的xml配置文件里面添加RatingBar控件。

     main.xml

android:isIndicator              RatingBar是否是一个指示器(用户无法进行更改)

android:numStars               显示的星型数量,必须是一个整形值,像“100”。

android:rating                    默认的评分,必须是浮点类型,像“1.2”。

android:stepSize                 评分的步长,必须是浮点类型,像“1.2”。

就这么简单,我们自定义属于自己的RatingBar,星级评分控件!

阅读全文

与android自定义进度条图片相关的资料

热点内容
bs刷装备建立后文件夹没有 浏览:77
找漫画看应该下载什么app 浏览:182
如何在vps上搭建自己的代理服务器 浏览:744
nginxphp端口 浏览:403
内脏pdf 浏览:152
怎么看云服务器架构 浏览:85
我的世界国际服为什么登不进服务器 浏览:996
微盟程序员老婆 浏览:930
intellij创建java 浏览:110
java连接odbc 浏览:38
启动修复无法修复电脑命令提示符 浏览:359
手机编程是什么 浏览:98
山东移动程序员 浏览:163
苏州java程序员培训学校 浏览:479
单片机液晶驱动 浏览:856
魔拆app里能拆到什么 浏览:132
新预算法的立法理念 浏览:145
wdcpphp的路径 浏览:136
单片机p0口电阻 浏览:927
浏览器中调短信文件夹 浏览:596