开发者

Android change text color on click

开发者 https://www.devze.com 2023-03-16 22:36 出处:网络
I changed my ActionDown and ActionUp colors to match my original color and the text/button now goes transparent.

I changed my ActionDown and ActionUp colors to match my original color and the text/button now goes transparent.

My style script:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MenuFont">
    <item name="android:textSize">20sp</item>
    <item name="android:textColor">#CDCDCD</item>
    <item name="android:textStyle">normal</item>
    <item name="android:clickable">true</item>
    <item name="android:layout_weight">1</item>
    <item name="android:gravity">left|center</item>
    <item name="android:paddingLeft">35dp</item>
    <item name="android:layout_width">175dp</item> 
    <item name="android:layout_height">fill_parent</item>
</style>

Original working script:

package com.pxr.tutorial.menu;

import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class CustomTouchListener implements View.OnTouchListener {     
public boolean onTouch(View view, MotionEvent motionEvent) {

    switch(motionEvent.getAction()){            
        case MotionEvent.ACTION_DOWN:
         ((TextView) view).setTextColor(0xFF6A5ACD); 
            break;          
        case MotionEvent.ACTION_CANCEL:             
        case MotionEvent.ACTION_UP:
        ((TextView) view).setTextColor(0xFFFFFF00);
            break;
    } 

    return false;   
} 
}

New Script:

package com.synamegames.orbs;

import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class CustomTouchListener implements View.OnTouchListener {     
public boolean onTouch(View view, MotionEvent motionEvent) {

    switch(motionEvent.getAction()){            
        case MotionEvent.ACTION_DOWN:
         ((TextView) view).setTextColor(0x4F4F4F); 
            break;          
        case MotionEvent.ACTION_CANCEL:             
        case MotionEvent.ACTION_UP:
        ((TextView) view).setTextColor(0xCDCDCD);
            break;
    } 

    return fals开发者_JAVA百科e;   
} 
}

What i did was change the hex codes to match the original text color. Once i did that the text became transparent when clicked. What did i do wrong?


Use 0xFF4F4F4F instead of 0x4F4F4F. And 0xFFCDCDCD instead of 0xCDCDCD.

00..FF is alpha value which stands for transparency.

0

精彩评论

暂无评论...
验证码 换一张
取 消