android - ProgressDialog 是否可绘制? GIF 什么的?

标签 android android-asynctask gif progressdialog android-drawable

我正在进行注册 Activity ,其中我使用可绘制资源进行交互。 TextWatcher 和一些编码,然后(示例):

etPass.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_lock_open, 0, R.drawable.icon_close, 0);

现在,我做了一个任务来检查数据库中的电子邮件。我想在此任务获得结果时显示 ProgressDialog。我尝试使用 gif,但动画效果不佳。我想要这样的东西:

注意:我想通过“setCompoundDrawablesWithIntrinsicBounds”执行此操作,一旦它已经格式化并适合现场。但我对其他方式持开放态度。

谢谢!

最佳答案

这是我的做法:

使用 ProgressBarEditText 创建自定义 XML。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <EditText 
        android:layout_width="match_parent"
        android:id="@+id/edit"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/ic_launcher" 
        android:singleLine="true" />
    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:id="@+id/progress"
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/edit"
        android:layout_alignBottom="@id/edit"
        android:layout_alignRight="@id/edit"/>
</RelativeLayout>  

然后,将其包含在 Activity 中

<include
        android:id="@+id/field1"
        layout="@layout/progress_edittext"
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />  

然后在onCreate() 中获取它

public class MainActivity extends ActionBarActivity {
    private View field1;
    private EditText edit;
    private ProgressBar progress;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        field1 = findViewById(R.id.field1);
        edit = (EditText) field1.findViewById(R.id.edit);
        progress = (ProgressBar) field1.findViewById(R.id.progress);
        edit.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                progress.setVisibility(View.VISIBLE);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {}

            @Override
            public void afterTextChanged(Editable s) {
                // YOUR LOGIC GOES HERE
            }
        });
    }
}

关于android - ProgressDialog 是否可绘制? GIF 什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32718836/

相关文章:

Android 开发,源文件组织/符号最佳实践?

java - Android:Android 应用程序中的所有 Activity 是在同一个线程中运行还是在它们自己的单独线程中运行?

android - 如何使用列表中的异步任务从android中的房间表获取所有数据

python - 是否可以仅使用枕头库生成 gif 动画?

android - 如何使用 Facebook Android SDK 3.8 获取 facebook 访问 token ?

java - 使用 setLayoutParams 循环 - ClassCastException

Java异步调用方法等待返回

android - 当从抽屉导航的每个列表项发出请求时,AsyncTask 执行需要在同一 fragment 中取消

jsf/primefaces 在 bean 初始化期间加载指示器

带有大动画 gif 图像的 Android 自定义通知