我想在activity的某些处理过程中在editText的右侧显示progressbar(微调),并在完成时隐藏,有没有简单的方法来做到这一点?android progressbar inside edittext
12
A
回答
25
我会用RelativeLayout
,像这样:
<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
尝试......
<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
晚的答案,但是,也许有人会利用这一点。
我创建了一个新的视图,实际上是为我完成这项工作。
所以,首先,创建布局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>
现在,一个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;
}
}
定义你的属性,所以你可以在XML中使用它。
<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"/>
您在活动/片段instansiate对象:在你的价值观的文件夹,创建一个.xml文件名为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>
最后,在你使用它的活性/片段。当你要拨打的进度栏是可见的,只需键入
mEditText.setRefreshing(true/false);
+0
您可以添加您所使用的color.xml和dimen.xml值? – 4gus71n 2016-12-27 21:08:01
相关问题
- 1. edittext inside tablerow android
- 2. edittext inside scrollview,如何在获取焦点时滚动到edittext
- 3. Android ViewFlipper Inside ScrollView
- 4. Android - Recycleview Inside Scrollview
- 5. RecyclerView inside NestedScrollView Android
- 6. 左侧的Edittext中的Tiny Circular ProgressBar
- 7. Android ProgressBar getProgress?
- 8. Android WebView Onclick ProgressBar
- 9. android circle progressbar
- 10. Android - progressbar或seekbar或?
- 11. Android ProgressBar倒计时
- 12. Android ProgressBar与线程
- 13. 的Android的EditText bacground
- 14. 如何在水平LinearLayout中垂直对齐EditText和ProgressBar?
- 15. Android EditText
- 16. Android EditText
- 17. Android progressBar setVisibility()不工作
- 18. Android新的ProgressBar没有NullPointerException?
- 19. Android:在ProgresDialog中使用ProgressBar
- 20. ProgressBar不断加载(Android)
- 21. Android ProgressBar没有动画
- 22. 用Xamarin显示Android ProgressBar
- 23. 在Android ListView中消失ProgressBar
- 24. 通知中的ProgressBar [ANDROID]
- 25. EditText Android,[new to android]
- 26. 如果EditText inside被禁用,如何更改TextInputLayout的浮动提示颜色
- 27. jquery .inside()?
- 28. Edittext android automatic focus
- 29. Android EditText onClickListener
- 30. android asynctask edittext
谢谢那正是我一直在寻找 – mkso 2010-12-20 22:24:26