Chcę wyświetlić pasek postępu (pokrętło) po prawej stronie editText, gdy aktywność jest przetwarzanie i ukryć po zakończeniu, czy istnieje prosty sposób to zrobić?Android progressbar wewnątrz edittext
12
A
Odpowiedz
25
użyję RelativeLayout
, coś takiego:
<RelativeLayout>
<EditText
android:id="@+id/the_id"/>
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_alignTop="@id/the_id"
android:layout_alignBottom="@id/the_id"
android:layout_alignRight="@id/the_id"/>
</RelativeLayout>
7
spróbować tego ...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:ems="10"
android:hint="@string/app_name"
android:inputType="textNoSuggestions"
android:padding="8dp" >
</EditText>
<ProgressBar
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/editText"
android:layout_alignRight="@id/editText"
android:layout_alignTop="@id/editText" />
</RelativeLayout>
</LinearLayout>
3
Późne odpowiedź, ale może ktoś użyje tego.
Stworzyłem nowy widok, który faktycznie wykonuje zadanie dla mnie.
Tak, przede wszystkim, tworzenie układu 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"
android:orientation="vertical">
<com.view.InstantAutoComplete
android:id="@+id/custom_edit_text_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/layout_padding"/>
<ProgressBar
android:id="@+id/custom_edit_text_progress_bar"
style="@style/SmallProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:visibility="gone"/>
</RelativeLayout>
Teraz klasę Java:
public class CustomEditText extends RelativeLayout {
private LayoutInflater mInflater = null;
private AutocompleteEditText mEditText;
private ProgressBar mProgressBar;
private boolean mIsRefreshing = false;
private int textColor;
private int hintTextColor;
private String hint;
private int textSize;
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
initViews(attrs);
}
public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initViews(attrs);
}
private void initViews(AttributeSet attrs) {
mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mInflater.inflate(R.layout.custom_layout_edit_text, this, true);
mEditText = (AutocompleteEditText) findViewById(R.id.custom_edit_text_edit_text);
mProgressBar = (ProgressBar) findViewById(R.id.custom_edit_text_progress_bar);
mProgressBar.getLayoutParams().height = mEditText.getLayoutParams().height - 30;
mProgressBar.getLayoutParams().width = mEditText.getLayoutParams().height - 30;
mProgressBar.requestLayout();
TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.CustomEditText, 0, 0);
try {
textColor = a.getInteger(R.styleable.CustomEditText_textColor, R.color.black);
hint = a.getString(R.styleable.CustomEditText_hint);
hintTextColor = a.getInteger(R.styleable.CustomEditText_hintTextColor, R.color.black);
textSize = a.getDimensionPixelSize(R.styleable.CustomEditText_textSize, R.dimen.text_medium_size);
} finally {
a.recycle();
}
mEditText.setTextColor(textColor);
mEditText.setHint(hint);
mEditText.setHintTextColor(hintTextColor);
mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
public void setRefreshing(boolean isVisible) {
if (isVisible) {
if (!mIsRefreshing) {
mIsRefreshing = true;
mProgressBar.setVisibility(VISIBLE);
}
} else {
if (mIsRefreshing) {
mIsRefreshing = false;
mProgressBar.setVisibility(GONE);
}
}
}
public AutocompleteEditText getEditText() {
return mEditText;
}
public ProgressBar getProgressBar() {
return mProgressBar;
}
}
Określ swoje atrybuty, dzięki czemu można go używać w xml. W katalogu wartości, utwórz plik .xml nazwanych attrs:
<resources>
<declare-styleable name="CustomEditText">
<attr name="hint" format="string"/>
<attr name="textColor" format="color"/>
<attr name="textSize" format="dimension"/>
<attr name="hintTextColor" format="color"/>
</declare-styleable>
</resources>
I wreszcie używać go w sobie aktywność/fragment jak:
<com.CustomEditText
android:id="@+id/reply_to_request_main_course_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/layout_padding"
android:layout_weight="1"
app:textColor="@color/black"
app:textSize="@dimen/text_medium_size"/>
Ty instansiate obiekt w działaniu/fragmentu. Gdy chcesz wywołać pasek postępu będzie widoczny, wystarczy wpisać
mEditText.setRefreshing(true/false);
+0
mógłbyś dodać wartości color.xml i dimen.xml że korzystałeś? – 4gus71n
Powiązane problemy
- 1. Odliczanie Android ProgressBar
- 2. Przewijanie EditText wewnątrz ScrollView
- 3. Android ProgressBar UI niestandardowy układ
- 4. Android - programowo tworzy widok progressBar
- 5. Centrowanie ProgressBar programowo w Android
- 6. Zmiana rozmiaru EditText wewnątrz AlertDialog
- 7. Android Custom EditText z ikoną
- 8. Android Edittext- Clearing Spans
- 9. Edittext in Listview android
- 10. android - jak wypełnić Edittext?
- 11. Android EditText i addTextChangedListener
- 12. Android EditText Max Length
- 13. android EditText podpowiedź problem
- 14. wejście EditText wzorkiem android
- 15. Android: Jak zmienić wysokość paska ProgressBar?
- 16. ProgressBar i progressBarStyleHorizontal wyściółka
- 17. Wybierz tekst do skopiowania Android EditText
- 18. Czy można zmienić rozmiar ikony wewnątrz EditText?
- 19. Android: EditText - wiele linii i android: inputType
- 20. SwingWorker ProgressBar
- 21. edittext android z rozwijaną listą
- 22. Sprawdzanie poprawności Android EditText Preferencje
- 23. mapowania znaków w EditText android
- 24. Linia Zmień Kolor EditText - Android
- 25. Android newline w moim EditText
- 26. Android: Problemy z animacją edittext?
- 27. Android: EditText w ListView wydanie
- 28. Konwertowanie EditText na int? (Android)
- 29. Android kursor tekstowy w EditText
- 30. Python QT ProgressBar
Dziękuję to dokładnie to, czego szukałem – mkso