[英]How to change setBackground color and show tick image on click a button in android
<RelativeLayout
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/checkimage"
android:layout_width="16dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:visibility="gone"
android:src="@drawable/greentickmark"
android:layout_height="16dp" />
<LinearLayout
android:id="@+id/clicklayout"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/click"
android:layout_gravity="center"
android:background="@drawable/background"
android:layout_width="60dp"
android:layout_height="50dp" />
<TextView
android:textStyle="bold"
android:textSize="10dp"
android:layout_marginTop="4dp"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
如果我單擊單擊id id Image View,則布局背景顏色已更改,但檢查圖像不可見。如何顯示此檢查圖像並更改背景顏色。
public void onClick(View v) { checkimage.setVisibility(View.VISIBLE);
clicklayout.setBackgroundColor(Color.parseColor("#2f0058")); }
<RelativeLayout
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/clicklayout"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/click"
android:layout_gravity="center"
android:background="@drawable/background"
android:layout_width="60dp"
android:layout_height="50dp" />
<TextView
android:textStyle="bold"
android:textSize="10dp"
android:layout_marginTop="4dp"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="@+id/checkimage"
android:layout_width="16dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:visibility="gone"
android:src="@drawable/greentickmark"
android:layout_height="16dp" />
</RelativeLayout>
您的線性布局與imageview重疊,因此..希望這會有所幫助..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.