我正在搜索如何改变背景颜色的点击gridview项目时,它被点击,然后回到正常的颜色
我希望当我点击,我的gridview项目的背景颜色是橙子,然后在很短的时间后,背景是白色了。
这是我发现的,但“设备”是未知的。
e.View.SetBackgroundColor(Color.White);
Device.StartTimer(TimeSpan.FromSeconds(0.25), () =>
{
e.View.SetBackgroundColor(Color.Orange);
return false;
});
我试过这个:
1.通过在值中创建colors.xml来定义颜色
972234 #000000
1.在drawable中创建bg_key. xml
1.将android:listSelector和listSelector设置为GridView
〈GridView xmlns:android=”http://schemas.android.com/apk/res/android“android:id="@+id/gridview”android:layout_width=“fill_parent”android:layout_height=“fill_parent”android:columnWidth=“90dp”android:numColumns=“auto_fit”android:verticalSpacing=“10dp”android:horizontalSpacing =“10dp”android:stretchMode=“columnWidth”android:gravity=“center”
android:listSelector="@drawable/bg_key"
android:background="@color/default_color"
/>
而且它在我的侧菜单上工作,但不在我的网格视图上...我的网格视图是由一个ImageView和一个TextView组成的,这是问题所在吗?
另外,我应该改变什么(对于我的侧菜单)来改变字体颜色而不是背景颜色?
下面是我的代码:
Main.axml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EBEAEF">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:paddingLeft="5dp"
android:background="#282059"
android:title="test"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- The Main Content View -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logoBackgroud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/icon_background" />
<GridView
android:id="@+id/grid_view_image_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="350dp"
android:layout_margin="10dp"
android:gravity="center"
android:numColumns="auto_fit" />
</RelativeLayout>
gridview.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EBEAEF">
<RelativeLayout
android:layout_height="90dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_margin="25dp"
android:listSelector="@drawable/bg_key"
android:background="#F4F4F6">
<!-- Letter yellow color = #FAB322 -->
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="95dp"
android:layout_height="fill_parent"
android:textSize="66sp"
android:textColor="#0071CF"
android:background="@color/white"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:gravity="center_vertical|center_horizontal"
android:text="A"
android:paddingBottom="5dp"
android:id="@+id/textViewLetter" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="15dp"
android:layout_toRightOf="@+id/textViewLetter"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:textSize="22sp"
android:gravity="center_vertical"
android:background="#F4F4F6"
android:textColor="#262057"
android:textStyle="bold"
android:listSelector="@drawable/bg_key"
android:id="@+id/textViewFileName" />
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:layout_alignParentRight="true"
android:id="@+id/imageViewIcon" />
</RelativeLayout>
</LinearLayout>
2条答案
按热度按时间djp7away1#
您不能使用
Device
-Class,因为它只在Xamarin.Forms中可用,而不是原生Xamarin。但是你可以使用
System.Timers.Timer
类在一段时间后将颜色改回来:重要提示:
Elapsed
-事件是NOT invoked on the UI-Thread。因此,要更改UI上的某些内容(就像您的背景颜色),您需要在UI线程上执行此操作。4jb9z9bj2#
Device.StartTimer
在Xamarin.Forms中用于使用设备时钟功能启动循环计时器。它在本机中不可用。我更喜欢你可以做一个定制的风格。
试试这个:
1)通过在
values
中创建colors.xml
来定义颜色2)在
drawable
中创建bg_key.xml
3)将
android:listSelector
和listSelector设置为GridView