我正在給AlertDialog充氣以讓用戶發送評論。相當簡單。但我發現了這個皮棉警告:對話框中的按鈕順序
佈局使用了錯誤的按鈕,以便API> = 14:創建 相反順序佈局-V14/chat_comment_dialog.xml文件:取消按鈕應在左邊(是「@字符串/發送|取消」,應該是「取消| @字符串/ 派」)
所以,是的,這是解決方案,創建API> = 14特定的佈局和顛倒順序。但是....真的嗎?這真的是官方建議嗎?要在某些設備中設置一個訂單而在其他設備中設置另一個訂單?作爲用戶,我會感到非常困惑。我應該忽略這個林特建議,或以其他方式,按照一組設備的這一新格局(我認爲這是相當混亂)
總之,這裏的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:singleLine="true" />
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="180dp"
android:gravity="top|left"
android:hint="@string/review" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="4dp"
android:text="@string/send"
android:textSize="18sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="4dp"
android:text="@android:string/cancel"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
順便說一句,我有來誇大XML中的按鈕而不是AlertDialog.Builder中的按鈕(也許這樣按鈕會自動排序),因爲您設置爲Builder的deafult按鈕的任何onClickListener都會關閉對話框,我必須避免這種行爲自己控制對話框。
你應該聽從建議,是的。儘管你可以不情願地跟隨,但你必須遵循。當然你可以有一個單獨的確定/取消佈局(2個版本),並且它可以在任何地方使用。 – 2012-07-19 15:08:39
「但是......真的嗎?這真的是官方的建議嗎?」是的,它肯定是= /他們改變了API級別對話框上按鈕的默認順序。如果您使用構建器而不是通過xml佈局創建對話框,則也會看到此更改。這是否是一個好主意肯定有爭議,但他們卻選擇了這個主意。 – FoamyGuy 2012-07-19 15:26:51