在相对布局上更改touchevent的背景颜色(Changing background color on touchevent on relative layout)

编程入门 行业动态 更新时间:2024-10-27 04:34:42
在相对布局上更改touchevent的背景颜色(Changing background color on touchevent on relative layout)

我正在使用以下代码。

<RelativeLayout android:layout_width="310dp" android:layout_height="70dp" android:layout_below="@+id/UIReportView" android:layout_marginLeft="4dp" android:layout_marginTop="2dp" android:background="@drawable/small_corners" >

small_corners

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/UINoCorners" android:shape="rectangle"> <corners android:radius="10dp"/> <padding android:left="10dp" android:right="10dp" android:top="5dp" android:bottom="5dp"/> <solid android:color="#FFFFFF"/> </shape>

现在,它显示一个白色条。 我想要的是,每当我点击这个相对布局时,它的颜色应该由我设定。

report = (RelativeLayout) findViewById(R.id.UIMainReportViewTimely); report .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // My Code } });

我应该在这里做什么? report.onTouchEvent?

我怎样才能改变背景的颜色。

最好的祝福

i am using following code.

<RelativeLayout android:layout_width="310dp" android:layout_height="70dp" android:layout_below="@+id/UIReportView" android:layout_marginLeft="4dp" android:layout_marginTop="2dp" android:background="@drawable/small_corners" >

small_corners

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/UINoCorners" android:shape="rectangle"> <corners android:radius="10dp"/> <padding android:left="10dp" android:right="10dp" android:top="5dp" android:bottom="5dp"/> <solid android:color="#FFFFFF"/> </shape>

Now , it shows a white bar. I want that, whenever i click on this relative layout its color should change, set by me.

report = (RelativeLayout) findViewById(R.id.UIMainReportViewTimely); report .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // My Code } });

What should i do here? report.onTouchEvent?

And how can i change the color of background.

Best Regards

最满意答案

你可以使用这个: -

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <stroke android:width="1dp" android:color="#999999" /> <padding android:left="10dp" android:top="3dp" android:right="10dp" android:bottom="3dp" /> <corners android:radius="7dp" android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" /> <gradient android:startColor="#449def" android:endColor="#2f6699" android:angle="270" /> </shape> </item> <item> <shape> <corners android:radius="10dp"/> <padding android:left="10dp" android:right="10dp" android:top="5dp" android:bottom="5dp"/> <solid android:color="#FFFFFF"/> </shape> </item> </selector> </shape>

you can use this:-

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <stroke android:width="1dp" android:color="#999999" /> <padding android:left="10dp" android:top="3dp" android:right="10dp" android:bottom="3dp" /> <corners android:radius="7dp" android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" /> <gradient android:startColor="#449def" android:endColor="#2f6699" android:angle="270" /> </shape> </item> <item> <shape> <corners android:radius="10dp"/> <padding android:left="10dp" android:right="10dp" android:top="5dp" android:bottom="5dp"/> <solid android:color="#FFFFFF"/> </shape> </item> </selector> </shape>

更多推荐

android,report,dp,color,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-04-29 10:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   颜色   背景   touchevent   Changing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!