【发布时间】:2012-07-01 23:56:58
【问题描述】:
我想在 android edittextpreference 上放一个按钮。 我创建了一个自定义的editextpreference:
public class EditTextPreferenceWithButton extends EditTextPreference {
private Context context;
public EditTextPreferenceWithButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context=context;
}
public EditTextPreferenceWithButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.context=context;
}
public EditTextPreferenceWithButton(Context context) {
super(context);
this.context=context;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
view.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
final EditText editText = (EditText)view.findViewById(android.R.id.edit);
ViewGroup vg = (ViewGroup)editText.getParent();
Button button = new Button(context);
vg.addView(button,ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
通过这种方式,按钮显示在编辑文本下方,但我希望它是下一个编辑文本,如下所示:
|编辑文本| |按钮|
请帮帮我! 谢谢
【问题讨论】:
-
您想要一个带有右侧按钮的编辑文本,以便将它们添加到对话框中?
-
是的。在单击 edittextpreference 行时显示的对话框中。
-
看我的回答,这就是你要找的吗?