在相对布局上更改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
发布评论