import com.ohos.agp.components.Text; import com.ohos.agp.components.ComponentContainer; import com.ohos.agp.utils.Color; public class TextColorAbility extends Ability { @Override public void onStart(Intent want) { super.onStart(want); super.setUIContent(createLayout()); } private ComponentContainer createLayout() { Text text = new Text(getContext()); text.setText("Hello World"); text.setTextColor(Color.RED); // 添加点击事件来获取文字颜色 text.setClickedListener(component -> { Color textColor = text.getTextColor(); Log.info("Text color: " + textColor.toHexString()); }); return new ColumnLayout(getContext(), new Component[]{text}); } }