android action bar progress

setContentView前调

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

显示progress

setProgressBarIndeterminateVisibility(true);

隐藏progress

                setProgressBarIndeterminateVisibility(false);

一般常用到获取列表数据的activity里。

注意:用上面的代码前提是

extends ActionBarActivity 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 中,可以使用以下步骤一次上传多张图片: 1. 在布局文件中添加一个 RecyclerView,并创建一个适配器来显示所有选定的图片。 2. 创建一个方法来选择多张图片。可以使用系统提供的 Intent.ACTION_GET_CONTENT 操作来打开系统图片选择器。 3. 在 onActivityResult 方法中获取选择的图片,并将它们添加到 RecyclerView 中。 4. 创建一个方法来上传所有选定的图片。可以使用 HTTP POST 请求将图片发送到服务器,并在上传期间显示进度条或通知。 以下是示例代码: 1. 布局文件中添加 RecyclerView: ```xml <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical" /> ``` 2. 创建一个方法来选择多张图片: ```java private void selectImages() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGES); } ``` 3. 在 onActivityResult 方法中获取选择的图片,并将它们添加到 RecyclerView 中: ```java @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGES && resultCode == RESULT_OK) { if (data.getClipData() != null) { int count = data.getClipData().getItemCount(); for (int i = 0; i < count; i++) { Uri imageUri = data.getClipData().getItemAt(i).getUri(); // Add the image to the RecyclerView adapter mAdapter.addItem(imageUri); } } else if (data.getData() != null) { Uri imageUri = data.getData(); // Add the image to the RecyclerView adapter mAdapter.addItem(imageUri); } } } ``` 4. 创建一个方法来上传所有选定的图片: ```java private void uploadImages(List<Uri> images) { // Show a progress bar or notification during the upload process // ... // Upload each image using an HTTP POST request for (Uri imageUri : images) { File imageFile = new File(getRealPathFromURI(imageUri)); RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), imageFile); MultipartBody.Part imagePart = MultipartBody.Part.createFormData("image", imageFile.getName(), requestBody); // Send the HTTP POST request to the server // ... } // Hide the progress bar or notification after the upload is complete // ... } private String getRealPathFromURI(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, projection, null, null, null); if (cursor == null) return null; int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String filePath = cursor.getString(column_index); cursor.close(); return filePath; } ``` 注意,这只是一个基本的示例代码,需要根据实际情况进行修改和优化。例如,应该处理上传失败和网络错误的情况,并在上传期间显示适当的错误消息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值