我擁有最新的Android Studio和SDK(編譯SDK 21,構建工具21.1.2,appcompat v7 21.0.3)並使用空白活動模板創建一個全新的嚮導應用程序。Android按鈕在Jellybean上是半透明的,但不在Lollipop上
然後我只更改XML:根相對佈局(android:background =「#00FF00」)的背景並添加一個按鈕(使用圖形編輯器,不更改按鈕)。
這適用於棒棒糖設備。在糖果軟糖(4.2.2)設備或模擬器上,該按鈕以灰色呈綠色觸摸呈現。
這可能是一個主題(Theme.AppCompat.Light.DarkActionBar),但它應該不會在Lollipop和Jellybean設備上呈現相同的內容嗎?
我看過關於手動更改按鈕背景的問題(例如How to make button non transparent),這是一個兼容性問題。
以下是完整的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#00FF00">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp"
android:layout_marginTop="55dp" />
</RelativeLayout>
有趣的方法。一個人必須使用「@android:drawable/btn_default」,但它的工作原理。 – 2015-04-04 08:10:18