2010-02-02 72 views

回答

3

有很多方法可以做到這一點。

這樣做的最簡單的方法是用各種View屬性,如android:focusableandroid:focusableInTouchModeandroid:clickableTextView屬性,如android:selectAllOnFocus玩耍。

您還可以通過將背景設置爲StateListDrawable(也稱爲可繪圖)來自定義視圖的外觀。

7

我無法使羅馬的方法奏效,但我找到了我的答案here。使用XML資源作爲背景可繪製,瞧!它的工作就像一個魅力。

13

我supperpose 2佈局

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 

    > 

    <LinearLayout 
     android:id="@+id/root" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="?android:attr/selectableItemBackground" 
     android:clickable="true" 
     > 
... 
    </LinearLayout> 
</LinearLayout> 

findViewById(R.id.root).setOnClickListener(...); 
+0

這一個是偉大的! – 2015-08-23 01:45:56

+0

你的提示selectableItemBackground對我來說就像一個魅力。應該是被接受的答案! – rxDroid 2016-03-10 13:56:22

相關問題