我希望把Android上edittextpreference一個按鈕。 創建自定義editextpreference:EditTextPreference使用按鈕
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);
}
}
這樣的按鈕顯示編輯文本的下方,但我想它是未來像這樣的EditText:
|的EditText | |按鈕|
請幫幫我! 謝謝
你想要一個帶右邊的按鈕的edittext,你將它添加到對話框中? –
是的。在點擊edittextpreference行時顯示的對話框中。 – user1437101
看到我的答案,那是你在找什麼? –