如何在 Xamarin.android 中更改条目光标颜色 [英] How to change Entry cursor color in Xamarin.android

查看:22
本文介绍了如何在 Xamarin.android 中更改条目光标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中需要更改 xamarin.android 条目的默认颜色.在我的应用程序中,背景图像是黑色,并且 xamarin.android 中条目的默认颜色也是相同的颜色,因此需要设置不同的颜色.请提出任何想法.我正在尝试休耕代码,但没有得到确切的结果.

In my application need to change xamarin.android entry default color. In my application background image is black and default color of entry in xamarin.android also same color, so need to set different color. Please suggest any idea on that. I am trying fallowing code but I am not getting exact result.

在我的 xamarin.android 项目文件夹中,values 文件夹中包含资源文件夹,我们有文件 'styles.xml' 文件.在这样的样式标签中,这是项目名称colorAccent".

In my xamarin.android project folder contain resource folder inside values folder, we have file 'styles.xml' file. In that is item name 'colorAccent' inside style tag like this.

示例代码:

 <style name="MainTheme.Base" parent="Theme.AppComa.Light.DarkActionBar">
   <item name="colorAccent">#ffffff</item>
 </style>

在 colorAccent 项目名称默认设置为黑色,现在我更改为白色,但是当运行这样的项目时,所有条目光标颜色更改为白色,但使用光标,条目颜色也更改为白色.我的要求只是改变了输入光标的颜色,其余都是一样的.

In colorAccent item name default set as black, now I am change in to white but when run project like this all entry cursor color change to white but with cursor, entry's color also change to white. My requirement is only changing the entry cursor color, remaining is same.

推荐答案

如果您要为活动指定主题,您还可以定义自定义主题并将 android:textCursorDrawable 设置为 @null.在这种情况下,光标颜色将与文本颜色相同.

If you're specifying theme for an activity, you can also define custom theme and set android:textCursorDrawable to @null. In that case cursor color will be the same as text color.

这是我的工作 values/Styles.xml 中的一个示例,请注意最后一个项目标签:

Here's an example from my working values/Styles.xml, note the last item tag:

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <style name="Project.Main" parent="android:Theme.Holo.Light">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:textCursorDrawable">@null</item>
  </style>
</resources>

已编辑

如果您希望光标颜色与文本颜色不同,则需要创建 EntryRenderer.并将以下行放在 Renderer 类的 OnElementChanged

If you want different cursor color to text color then you need to create EntryRenderer. and put following line in OnElementChanged of your Renderer class

IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));
IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID (IntPtrtextViewClass, "mCursorDrawableRes", "I");
JNIEnv.SetField (Control.Handle, mCursorDrawableResProperty, 0); // replace 0 with a Resource.Drawable.my_cursor

这篇关于如何在 Xamarin.android 中更改条目光标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆