简体   繁体   English

如何更改setBackground颜色并在Android中单击按钮时显示刻度图像

[英]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>

If i click on click id Image View then layout background color is changed but check image is not visible.How to show this check image and change background color. 如果我单击单击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>

your linear layout overlaping the imageview so.. hope this helps.. 您的线性布局与imageview重叠,因此..希望这会有所帮助..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM