2013-11-01 50 views
-1

我有一個小問題。我不知道這是一個真正的問題還是隻是在Android模擬器中的錯誤。這是 - 我在窗體中有一個切換按鈕,它工作得很好,但是當我在Nexus 7仿真器上運行我的應用程序以在大型佈局上測試時,切換按鈕的綠色指示燈未顯示。只有文字可見。在我的Nexus 4(4.3)上,它工作得很好(以及其他幾款採用不同Android版本的設備)。這會發生在真實的設備上,還是隻是模擬器的錯誤?Android 4+上的切換按鈕外觀

enter image description here

+0

好了,它的那種含糊,但我要說試圖使該按鈕的高度大一點,只是爲了確保它不被收縮或東西。 –

+0

已經做到了,綠色指標不再顯示。 – mihail

回答

0

他們是在同一個版本的Android? Nexus 7的版本是4.1,而Nexus 4顯然是4.3。

如果您使用的是默認的ToggleButton風格,它會在不同版本的android上看起來不同。如果您希望它在多個版本中看起來相同,您可以創建一個選擇器並將其設置爲背景。

在你切換按鈕的xml:

android:background="@drawable/myselector" 

然後創建您的繪圖資源文件夾中的myselector.xml,並添加一些條件。這裏有一個我有一個複選框的示例。切換按鈕應該類似於:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/star_golden_pressed" /> 
    <item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/star_gray_pressed" /> 
    <item android:state_checked="true" android:drawable="@drawable/star_golden" /> 
    <item android:state_checked="false" android:drawable="@drawable/star_gray" /> 
</selector>