2016-12-15 8 views
0

Ich muss visuelles Feedback hinzufügen, wenn ein Benutzer auf meinen Rahmen klickt. Ich folgte einigen Vorschlägen aus ähnlichen Fragen, aber ich kann es nicht funktionieren und ich weiß nicht, warum es nicht funktioniert. Hier ist, was ich bisher getan haben:Visuelle Rückmeldung beim Klicken auf ein RelativeLayout

rectangle_visual_feedback.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_pressed="true" android:drawable="@drawable/rectangle_visual_feedback" /> 
</selector> 

rectangle_visual_feedback_selector.xml:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
<solid android:color="#40808080"/> 
<padding android:bottom="10dp" android:right="10dp" android:top="10dp" android:left="10dp"></padding> 
</shape> 

fragment.xml:

<LinearLayout 
     android:id="@+id/linearlayout_holder" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="?android:attr/selectableItemBackground" 
     android:clickable="true" 
     android:paddingBottom="3dp" 
     android:paddingLeft="10dp" 
     android:paddingRight="3dp" 
     android:paddingTop="10dp"> 

     <RelativeLayout 
      android:id="@+id/relativelayout_mainwrap" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="8dp" 
      android:background="@drawable/rectangle_visual_feedback_selector" 
      > 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:gravity="center" 
       android:orientation="horizontal"> 

       <ImageView 
        android:id="@+id/imageview_image" 
        android:layout_width="22dp" 
        android:layout_height="22dp" 
        android:src="@drawable/thehotel_b" /> 

       <com.hotelstayapp.android.custom.CustomTextView 
        android:id="@+id/customtextview_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:gravity="center_vertical" 
        android:textAllCaps="true" 
        android:textSize="16sp" /> 
      </LinearLayout> 

     </RelativeLayout> 
    </LinearLayout> 

Hier ist der Code innerhalb das Fragment, das ich verwende, um das RelativeLayout zu nennen:

RelativeLayout relativelayout_mainwrap = (RelativeLayout) view.findViewById(R.id.relativelayout_mainwrap); 
RelativeLayout relativelayout_mainwrap.setBackgroundColor(Color.parseColor("#" + Theme.BackColorOpacity + Theme.BackColor)); 

Irgendwelche Ideen, warum das nicht funktioniert?

+0

Sie haben bereits einen Hintergrund in XML mit 'android: background gegeben. Warum stellst du dann eine andere Hintergrundfarbe in Java ein? – Karakuri

+0

Versuchen Sie, Android zu entfernen: clickable = "true" vom übergeordneten Layout – student

Antwort

0

Für visuelles Feedback Sie erstellen können folgende ziehbar,

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:color="@color/colorAccent" android:state_pressed="true" /> 
    <item android:color="@color/navigation_icon_default" /> 
</selector> 

und setzen Sie diesen ziehbar auf Ihre relativen Hintergrund Layout.

Verwandte Themen