1

我正在進行註冊活動,我使用繪圖資源進行交互。 TextWatcher和一些編碼,然後(例如):? GIF或什麼?

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

現在,我犯了一個任務,檢查數據庫的電子郵件。我想在此任務獲得結果時顯示ProgressDialog。我嘗試了一個gif,但它沒有正確的動畫。我想是這樣的:

注意:我想通過「setCompoundDrawablesWithIntrinsicBounds」要做到這一點,一旦它已經自帶的格式,適合在球場上。但我接受其他方式。

謝謝!

+0

嘗試像[這](http://androidxref.com/5.1。 1_r6/xref/frameworks/base/core/res/res/drawable/progress_medium.xml) – pskink

回答

1

這是我會怎麼做:

創建爲EditTextProgressBar自定義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> 

然後,它包含在活動

<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 
      } 
     }); 
    } 
} 
+0

Works!謝謝 ! **注**:我不需要 'field1 = findViewById(R.id.field1); edit =(EditText)field1.findViewById(R.id.edit); (ProgressBar)field1.findViewById(R.id.progress);' 只需: ProgressBar progress =(ProgressBar)findViewById(R.id.progress_email); progress.setVisibility(View.VISIBLE);' –

+0

@VictorMilazzo但是如果你有多個'',對吧? :) –

1

如果您願意獲得GIF並將其拆分爲框架,AnimationDrawable課程將滿足您的需求。

+0

嘗試過,但沒有工作..我認爲這是因爲setCompoundDrawablesWithIntrinsicBounds需要一個可繪製的參數。不管怎麼說,還是要謝謝你 ! –

+0

AnimationDrawable是一種Drawable! 沒關係,另一個答案給了你你需要的東西 – JoeyJubb

+0

你說得對!但是該方法不接受AnimationDrawable作爲參數:/ –

相關問題