[英]Android change text color on click
I changed my ActionDown
and ActionUp
colors to match my original color and the text/button
now goes transparent
.我更改了我的ActionDown
和ActionUp
colors 以匹配我的原始颜色并且text/button
现在变为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 false;
}
}
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.使用 0xFF4F4F4F 而不是 0x4F4F4F。 And 0xFFCDCDCD instead of 0xCDCDCD.和 0xFFCDCDCD 而不是 0xCDCCDCD。
00..FF is alpha value which stands for transparency. 00..FF 是 alpha 值,代表透明度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.