网格项目上的Textview单击更改颜色

时间:2022-11-21 12:43:41

i want to change color for textview inside a Relative Layout sample showing with GridView , i want to change color of textview which is inside relaytivelayout on grid item click at its position .

我想在使用GridView显示的相对布局示例中更改textview的颜色,我想要更改textview的颜色,该颜色位于网格项目单击其位置的relaytivelayout内部。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rel_bg"
android:layout_width="60dp"
android:layout_height="30dp"
android:background="@drawable/grid_item_bg"
android:orientation="vertical">

<TextView
    android:textColor="@drawable/state_rel"
    android:id="@+id/bTxt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="ABC"
    android:textSize="18sp" />

as i did with relativeLayout on grid Item clicked change background, facing problem in textview how to code for textview did nto understand this kindly please help :) thanks

正如我对网格上的relativeLayout所做的那样点击了更改背景,面对textview中的问题如何为textview编写代码请不要理解这一点请帮助:)谢谢

1 个解决方案

#1


0  

In the .java file, very like acitvity_main:

在.java文件中,非常像acitvity_main:

First you have to initialize your TextView by saying: TextView myTextView = (TextView) findViewById(R.id.myid);

首先,您必须通过以下方式初始化TextView:TextView myTextView =(TextView)findViewById(R.id.myid);

Than you can simply say: myTextView.setBackGroundColor(Color.argb(x1,x2,x3,x4);

比你可以简单地说:myTextView.setBackGroundColor(Color.argb(x1,x2,x3,x4);

x1 - x4 can get a value from 0 to 250. 0 is very light, 250 is very dark.

x1 - x4可以得到0到25​​0之间的值.0非常轻,250非常暗。

x1 = the opacity;

x1 =不透明度;

x2 = red;

x2 =红色;

x3 = green;

x3 =绿色;

x4 = blue;

x4 =蓝色;

An example: myTextView.setBackgroundColor(Color.argb(250,250,0,0); would set a very red Background.

例如:myTextView.setBackgroundColor(Color.argb(250,250,0,0);会设置一个非常红的背景。

#1


0  

In the .java file, very like acitvity_main:

在.java文件中,非常像acitvity_main:

First you have to initialize your TextView by saying: TextView myTextView = (TextView) findViewById(R.id.myid);

首先,您必须通过以下方式初始化TextView:TextView myTextView =(TextView)findViewById(R.id.myid);

Than you can simply say: myTextView.setBackGroundColor(Color.argb(x1,x2,x3,x4);

比你可以简单地说:myTextView.setBackGroundColor(Color.argb(x1,x2,x3,x4);

x1 - x4 can get a value from 0 to 250. 0 is very light, 250 is very dark.

x1 - x4可以得到0到25​​0之间的值.0非常轻,250非常暗。

x1 = the opacity;

x1 =不透明度;

x2 = red;

x2 =红色;

x3 = green;

x3 =绿色;

x4 = blue;

x4 =蓝色;

An example: myTextView.setBackgroundColor(Color.argb(250,250,0,0); would set a very red Background.

例如:myTextView.setBackgroundColor(Color.argb(250,250,0,0);会设置一个非常红的背景。