将Button设置为类似EditText(但仍然像Button一样)

che*_*gon 7 android android-edittext android-button

我意识到这有点奇怪,但我有一个按钮需要看起来像一个EditText但仍然像按钮一样.我的布局XML目前看起来像这样:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="?android:attr/editTextStyle" />
Run Code Online (Sandbox Code Playgroud)

这给了它一个EditText的外观,但是由于阻止了onClick事件被触发,除非按钮具有焦点(有效地使它需要两次点击),所以还会稍微混淆行为.有没有办法保持风格而不改变按钮的行为?

我想过只做一个看起来像EditText的9补丁背景,但是有很多不同的Android版本和皮肤,我宁可使用系统风格,如果可能的话.

Zso*_*agy 28

EditText如何像按钮一样?

<EditText android:id="@+id/Edit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="true"/>
Run Code Online (Sandbox Code Playgroud)

您也可以为它定义OnClickListener.它不会得到关注.