我在使用 LinearLayout 包装的 EditText 控件旁边有一个 Button。一切似乎都很好,除了 Button 明显高于 EditText 并且我希望它具有相同的高度。@drawable/main_edittext 和@drawable/main_edittext_button 的高度相同,但即使没有设置背景,高度也不同。在应用程序清单文件中,应用程序主题仅设置为 windowNoTitle=true。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/main_background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/edit_message"
style="@style/MainEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message"
android:singleLine="true" />
<Button
android:id="@+id/edit_message_button"
style="@style/MainSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="@string/button_send" />
</LinearLayout>
<style name="MainEditText">
<item name="android:background">@drawable/main_edittext</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#262626</item>
</style>
<style name="MainSearchButton">
<item name="android:background">@drawable/main_edittext_button</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#ff5500</item>
</style>
+main_edittext.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/edit_text">
</item>
<item
android:state_enabled="true"
android:state_focused="true"
android:drawable="@drawable/edit_text">
</item>
<item android:state_enabled="true"
android:drawable="@drawable/edit_text">
</item>
</selector>
-main_edittext.xml
+main_edittext_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/edit_text_button">
</item>
<item
android:state_focused="true"
android:drawable="@drawable/edit_text_button">
</item>
<item android:drawable="@drawable/edit_text_button" />
</selector>
-main_edittext_button.xml