我使用Android 2.2手機創建了一個應用程序。我在活動中有四個切換按鈕。我在運行Android 4.2的平板電腦上查看了我的應用程序,並且指示燈不在按鈕的底部。Android 4.2無法正確顯示切換按鈕
我首先想到的是它可能會被截斷,所以我所做的按鈕高度200dp
,但是指示燈仍然不存在。
我也在以編程方式調整寬度,但評論它沒有幫助。
切換屏幕在運行Android 2.2的手機上正確顯示。
這裏是一個按鈕的XML:
<ToggleButton
android:id="@+id/cat_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_alignParentLeft="true"
android:textSize="12dp"
android:onClick="toggleClicked"
android:layout_marginLeft="10dp" />
我決定創建API 17的另一個項目,有一個單一的切換按鈕,它正確地顯示,所以我不知道是什麼原因造成的問題在我的第一個項目。
第二個項目形象和XML:使用自定義主題時
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="56dp"
android:layout_toRightOf="@+id/textView1"
android:text="ToggleButton" />
我會在'ToggleButton'上擺脫'onClick' - 請使用'setOnCheckedChangedListener()'來響應'ToggleButton'狀態的變化。此外,您的第一個項目是否使用可能會干擾「ToggleButton」樣式的自定義主題? – CommonsWare 2013-03-27 14:01:08
我只是使用'Theme.Black.NoTitleBar'。是使用所有按鈕上推薦的監聽器,還是隻是切換? 「 – Ryan 2013-03-27 14:02:36
」正在使用所有按鈕上推薦的偵聽器,或者只是切換?「 - 」ToggleButton「處理它自己的點擊事件,就像」CompoundButton「的所有子類一樣,因此使用'setOnCheckedChangedListener()'。 – CommonsWare 2013-03-27 14:04:06