我动态地在asynctask中创建了progressdialog.我为我的应用程序使用自定义样式.当我这样做,我的progressdialog风格改为白色我需要我的黑色默认风格与白色文本.
我的java文件:
class LoginTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(Login.this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Logging in...");
this.dialog.show();
}
// my prog
@Override
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}}
Run Code Online (Sandbox Code Playgroud)
我的style.xml:
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">@drawable/blue</item>
<item name="android:textColor">@color/white</item>
<item name="android:editTextColor">@color/white</item>
<item name="android:buttonStyle">@android:style/Widget.Holo.Button</item>
<item name="android:dropDownSpinnerStyle">@android:style/Widget.Holo.Spinner</item>
<item name="android:textAppearanceButton">@android:style/TextAppearance.Widget.Button</item>
<item name="android:progressBarStyle">@style/ProgressBar</item> …Run Code Online (Sandbox Code Playgroud) 我有一个ListView,其中每个项目代表一个PDF文件.当用户单击某个项目时,该应用程序必须在外部存储上下载该文件.现在下载无法正常运行,但这不是问题.我想要一个ProgressBar,旋转轮样式,在下载文件时出现在列表的每个项目旁边.
我的问题是:我找不到如何使纺车出现.在下载管理器之前,我尝试使用AsyncTask并且旋转轮工作.
这是我的代码:
CategoryActivity.java(ListView的活动)
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Récupère les valeurs depuis ListItem
udl = ((TextView) view.findViewById(R.id.udl)).getText().toString();
// This is the spinning wheel
loader = ((ProgressBar) view.findViewById(R.id.spinWheel2));
filepath = dirpath + udl + ".pdf";
File file = new File(filepath);
if (file.exists()) {
// If the file exists, I open it
}else{ // Else I download it
// Setting the spinning wheel to VISIBLE
loader.setVisibility(View.VISIBLE);
SharedPreferences codeSaveUrl = getSharedPreferences(PREFS_TEXT,Context.MODE_PRIVATE);
url2 = codeSaveUrl.getString("defaut", …Run Code Online (Sandbox Code Playgroud) android download-manager android-listview android-progressbar android-download-manager
我正在尝试创建一个薄的蓝色进度条,类似于:

我不是很好Drawables,但是我改变了ProgressBar绿色,但我不确定如何使它变得薄而蓝:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:visibility="gone"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
可绘制
<?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="#33FF33"
android:endColor="#008000"
android:angle="270" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) setProgressBarIndeterminateVisibility(false)不适用于2.3 android.我正在使用下面的代码.进度条始终显示,不会隐藏.相同的代码正在android 4.x上工作,进度条被隐藏.活动从SherlockFragmentActivity扩展,并且没有像setSupportProgressBarIndeterminateVisibility(true)这样的调用; 这将使进度条可见.我的完整代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
((SherlockFragmentActivity) JbActivity.this)
.requestWindowFeature((long) com.actionbarsherlock.view.Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setSupportProgressBarIndeterminateVisibility(false);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
restart = false;
actionBar = getSupportActionBar();
if (SelectedItems.isNull()) {
restart = true;
try {
String jsonString = savedInstanceState
.getString("SelectedItems");
SelectedItems.build(jsonString);
} catch (Exception e) {
Intent mainIntent = new Intent(JbActivity.this,CityList.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
finish();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我调用的代码中没有地方你可以建议一种方法,这样我就可以隐藏android 2.x上的进度条.谢谢
我有asynktask,显示progressDialog并在doInBackground方法中更新其值.方法代码:
@Override
protected void onPreExecute() {
progress = new ProgressDialog(cont);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
progress.setTitle(cont.getResources().getString(R.string.pleaseWait));
progress.setMessage(cont.getResources().getString(R.string.loadingImages));
progress.show();
super.onPreExecute();
}
@Override
protected String doInBackground(Void... arg0) {
progress.setProgress(2);
//do some work on the database and network
progress.setProgress(25);
//Do some extra work
for(int i = 0; i < itemImagesList.size(); i++){
publishProgress((int) ((i / (float) itemImagesList.size()) * 100));
//Do somework
}
}
@Override
protected void onProgressUpdate(Integer... prog) {
progress.setProgress(prog[0]);
}
@Override
protected void onPostExecute(String result) {
progress.dismiss();
super.onPostExecute(result);
}
Run Code Online (Sandbox Code Playgroud)
progressDialog值根本不会改变!如果我尝试使用以下方法设置对话框消息:
progress.setMessage("At item "+i);
Run Code Online (Sandbox Code Playgroud)
如果我把它放在方法的中间会发生一些异常,但在第一次它工作正常!
怎么了?
我在iOS上找到了一些改变微调器颜色的解决方案:
如何在iOS phonegap应用程序中显示自定义Splash Screen Spinner(即带有白色的微调器)?
在cordova-plugin-splashscreen中更改Splash Screen Spinner的颜色
...以及其他几个或多或少相关的问题,但没有什么可以改变android上启动画面的加载微调器的颜色.我的闪屏是蓝色的,旋转器是天蓝色的 - 不是真的可见 - 并且想把它变成白色.
我使用的cordova-plugin-splashscreen是https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/index.html,我使用本地构建我的应用程序cordova build android,并设法在我的设备上部署我的代码.但改变旋转器的颜色并没有好运.
platforms/android/src/org/apache/cordova/splashscreen/Splashscreen.java在创建ProgressBar对象时,我认为要编辑的代码是:
private void spinnerStart() {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
spinnerStop();
spinnerDialog = new ProgressDialog(webView.getContext());
spinnerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
spinnerDialog = null;
}
});
spinnerDialog.setCancelable(false);
spinnerDialog.setIndeterminate(true);
RelativeLayout centeredLayout = new RelativeLayout(cordova.getActivity());
centeredLayout.setGravity(Gravity.CENTER);
centeredLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
/* The following line here: */
ProgressBar progressBar = new ProgressBar(webView.getContext());
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, …Run Code Online (Sandbox Code Playgroud) 我有一个自定义循环进度条.这是我可以确定的可绘制的:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/secondaryProgress">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#999999"
android:endColor="#999999"
android:startColor="#999999"
android:type="sweep" />
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<rotate
android:fromDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
<gradient
android:centerColor="?attr/colorAccent"
android:endColor="?attr/colorAccent"
android:startColor="?attr/colorAccent"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我希望它以顺时针方向显示进度,但现在它显示逆时针方向.
我该如何改变它?
我有一项任务是ProgressBar在其上添加带有百分比值的值,以在用户想要预测某些内容时显示一个值。我没有使用,ProgressDialog因为它现在已被弃用。此处,百分比值取决于从请求开始到完成所用的时间。我正在使用Volley从服务器获取数据。
这是我要实现的目标的示例图像:
我已经这样做了
我在警报对话框中实现了一个水平进度条(我使用这种方式是因为进度对话框已被弃用)。我想像这样设置进度条。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_result_prediction, container, false);
predictProgress = (ProgressBar) view.findViewById(R.id.progressbarPredict);
AlertDialog.Builder(view.getContext());
builder.setCancelable(false); // if you want user to wait for some process to finish,
View v = inflater.inflate(R.layout.layout_loading_dialog, null);
builder.setView(v);
final AlertDialog dialog = builder.create();
submitPredictPlant.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.show();
predictProgress.setProgress(25);
predictProgress.setProgress(50);
predictProgress.setProgress(75);
predictProgress.setProgress(100);
dialog.dismiss();
Run Code Online (Sandbox Code Playgroud)
当进度为 100 时,我想关闭对话框。但这会出现类似错误
java.lang.NullPointerException: Attempt …Run Code Online (Sandbox Code Playgroud) 概括 :
使用图1作为参考。
我需要将灰色部分保留在绿色部分下方,以便当绿色减少时,灰色变得可见。但我也想要未覆盖的部分(只是灰色不存在)。导致 2/3 重叠圆。
我正在尝试在 android studio 中创建 2/3 圆(带圆角)作为进度条。我做不到。我希望得到你的帮助。
当前圈子:(图1)
我需要的圈子:
形状:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="ring" android:innerRadiusRatio="2.5" android:useLevel="false"
android:thicknessRatio="12">
<solid android:color="#DDD"/>
</shape>
</item>
<item>
<shape android:shape="ring" android:innerRadiusRatio="2.5" android:useLevel="true"
android:thicknessRatio="12">
<solid android:color="@color/colorAccent"/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/timerProgressBar"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
android:indeterminateOnly="false"
android:progressDrawable="@drawable/circle"
android:rotation="-90"
app:layout_constraintBottom_toTopOf="@+id/guidelineBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guidelineTop"
android:progress="10"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1" /> …Run Code Online (Sandbox Code Playgroud)