难道我学的是点击图片文字变亮?(多图)


看看,这些孩子,救救他们。



-----------------------------------ws

.在drawable文件夹下新建textcolor.xml文件,这里面可以引用颜色值也可以引用drawable,引用color就在colors.xml文件中用键值对定义相关的颜色,引用drawable那就colors.xml文件中用键值对定义相关的颜色,我们这里引用的是color,我也测试了drawable效果是一样的,因为颜色是一样的嘛,这里实际上也就是可以直接使用图片,但是我们没有图片就直接在资源文件中定义了,话说谁会给文字设置颜色的时候使用图片的呀,至少我还没有使用过呀.

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="false"
      android:state_enabled="true"
      android:state_pressed="false"
      android:color="@color/blue"/><!--选择器的默认颜色-->

    <item android:state_enabled="false"
      android:color="@color/black" /><!--控件是否接受触摸或者点击事件时的颜色,false不接受-->

    <item android:state_pressed="true"
      android:color="@color/green" /><!--是否按下,如一个按钮触摸或者点击,true按下-->

    <item android:state_focused="true"
      android:color="@color/red" /><!--是否取得焦点,true取的焦点-->
    </selector>
 <drawable name="red">#ff0000</drawable>
     <drawable name="green">#00ff00</drawable>
     <drawable name="blue">#0000ff</drawable>
     <drawable name="black">#000000</drawable>
     <drawable name="white">#ffffff</drawable>

     <color name="red">#ff0000</color>
     <color name="green">#00ff00</color>
     <color name="blue">#0000ff</color>
     <color name="black">#000000</color>
     <color name="white">#ffffff</color>

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.lwen.selectortest.MainActivity">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@drawable/textcolor"/>
    <TextView
        android:id="@+id/tv_text_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:textColor="@drawable/textcolor"
        android:text="文字测试"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按下文字颜色改变"
        android:textColor="@drawable/textcolor"
    />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮被禁用"
        android:enabled="false"
        android:textColor="@drawable/textcolor"
    />
</LinearLayout>

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        TextView tv_test = (TextView) findViewById(R.id.tv_text_test);
        tv_test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"按下获得焦点",Toast.LENGTH_SHORT).show();
            }
        });
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值