2011-10-18 59 views
0

我有一个非常简单的布局:带有MapView和ToggleButton的RelativeLayout。为什么当我没有在任何地方指定它时,ToggleButton显示为透明,真正的问题是,我怎样才能使它停止?Android - 谷歌地图上的透明ToggleButton

Transparent ToggleButton

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainlayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="true" 
    android:apiKey="NoYouCantSeeMyKey" /> 

<ToggleButton android:id="@+id/aerialsbutton" 
    android:layout_width="150px" 
    android:layout_height="50px" 
    android:textOn="Aerials On" 
    android:textOff="Aerials Off" 
    android:layout_alignParentRight="true" /> 

</RelativeLayout> 

我试过设置阿尔法为1,并且没有运气切换的MapView和切换按钮的顺序。任何帮助深表感谢。

更新:我有我的Applcation主题设置为android:theme="@android:style/Theme.Holo.NoActionBar"。这可能吗?

更新2:主题没有区别。在这里很难过。

+0

你试过 android:disabledAlpha 属性? –

+0

它没有帮助,也不应该因为我的ToggleButton没有被禁用。 – Gady

+0

你可以给setBackgroundDrawable(Drawable d) – Hanry

回答

0

您必须有一个主题或样式适用于它在其他地方定义。这不是默认的切换按钮样式。下面是我的一个测试项目几乎相同的XML的屏幕捕获的一部分 - 这显示了默认的切换按钮:

enter image description here

我希望这是一些使用的。

+0

谢谢,你在屏幕截图中对你的Togglebutton应用了什么主题/风格?我只想要Honeycomb的默认设置,我认为它是Holo。 – Gady

+0

我根本没有应用任何主题。我刚刚在API 11(蜂窝)仿真器上尝试过该应用程序,并且该按钮看起来与我的屏幕截图相同。 – NickT

+0

所以我刚刚在API 11上创建了一个新的应用程序,其中包含匹配的模拟器版本,没有设置任何样式或主题,并且ToggleButton在地图上仍然是透明的。你能否与我分享你的代码,以便我可以重现你如何得到不透明的按钮? – Gady

0

我解决了这个问题,只是增加的风格切换按钮标签:

<ToggleButton 
    android:id="@+id/my_toggle_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textOn="@string/toggle_button_on" 
    android:textOff="@string/toggle_button_off" 
    style="@android:style/Widget.Button.Toggle"/> 

我希望这有助于同样的问题别人。 :-)