Android 鼠标样式修改

Android 鼠标样式修改

Android 系统鼠标资源文件的位置:

/frameworks/base/core/res/res/drawable-mdpi/drawable/pointer_arrow_icon.xml

资源文件指定了鼠标不同分辨率下的图片资源:
/frameworks/base/core/res/res/drawable-mdpi/drawable/drawable-mdpi/pointer_arrow.png
/frameworks/base/core/res/res/drawable-mdpi/drawable/drawable-hdpi/pointer_arrow.png
/frameworks/base/core/res/res/drawable-mdpi/drawable/drawable-xhdpi/pointer_arrow.png
/frameworks/base/core/res/res/drawable-mdpi/drawable/drawable-xxhdpi/pointer_arrow.png

还有一个pointer_arrow_large.png图片,这个图片是适配大屏幕的设备的。

如果没有在代码中动态修改鼠标图片,那么默认就是显示上面位置的图片。

动态修改鼠标样式的代码:

下面的view_point是鼠标需要更新的图片坐标范围。

    private void setIconArrow() {
        PointerIcon pointerIcon = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_ARROW);//其中TYPE有一些系统定义的TYPE
        view_point.setPointerIcon(pointerIcon);
    }

//给View设置自定义的图片
//这里的load的resourceId需要是资源文件,不能是图片形式

    private void setIconOther() {
        view_point.setPointerIcon(PointerIcon.load(getResources(), R.drawable.pointer_other_icon));
    }

这个view_point可以是某个具体的View比如某个相对布局或者某一块区域的view,

也可以是Activity的Window DecorView比如:

getWindow().getDecorView().setPointerIcon(PointerIcon.load(getResources(), R.drawable.pointer_spot_touch_icon));

具体情况,要看你在哪个界面显示。

pointer_other_icon.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<pointer-icon
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:bitmap="@mipmap/ic_pointer_arrow_new" //设置图片
    android:hotSpotX="5dp"
    android:hotSpotY="5dp" />

PointerIcon源码位置: frameworks/base/core/java/android/view/PointerIcon.java

更多鼠标的设置:https://cloud.tencent.com/developer/article/1719663

共勉:夜深人静

### 回答1: 要改变Android的TextInputLayout的样式,可以在styles.xml文件中定义一个新的样式,然后将它应用到TextInputLayout控件上。 例如,要更改TextInputLayout的边框颜色和标签颜色,可以按照以下步骤操作: 1.在styles.xml文件中定义一个新的样式: ```xml <style name="MyTextInputLayoutStyle" parent="Widget.Design.TextInputLayout"> <!-- 边框颜色 --> <item name="boxStrokeColor">@color/my_color</item> <!-- 标签颜色 --> <item name="android:textColorHint">@color/my_color</item> </style> ``` 2.将新样式应用到TextInputLayout控件上: ```xml <com.google.android.material.textfield.TextInputLayout android:id="@+id/my_text_input_layout" style="@style/MyTextInputLayoutStyle" android:layout_width="match_parent" android:layout_height="wrap_content" app:hint="My Hint"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content"/> </com.google.android.material.textfield.TextInputLayout> ``` 这样就可以更改TextInputLayout的边框颜色和标签颜色了。您可以根据需要更改其他属性。 ### 回答2: Android的TextInputLayout是一个扩展的布局控件,用于实现漂亮的文本输入框。要改变其样式,我们可以通过以下步骤进行操作: 1. 首先,在项目的build.gradle文件中添加新的依赖项: ``` implementation 'com.google.android.material:material:<版本号>' ``` 请注意,这里的版本号可以根据你的项目需要进行调整。 2. 在布局文件中,将TextInputLayout作为容器包裹EditText控件,并设置所需属性,如hint、hintTextColor等。例如: ```xml <com.google.android.material.textfield.TextInputLayout android:id="@+id/textInputLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入内容" app:hintTextColor="@color/colorAccent"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content"/> </com.google.android.material.textfield.TextInputLayout> ``` 3. 使用代码动态修改样式。在Activity或Fragment中,可以通过findViewById方法获取到TextInputLayout对象,并设置所需的样式。例如,改变文本颜色: ```java TextInputLayout textInputLayout = findViewById(R.id.textInputLayout); textInputLayout.setHintTextColor(Color.RED); ``` 以上是使用Android的TextInputLayout改变样式的基本步骤。通过设置不同的属性和使用代码动态修改样式,可以实现丰富多样的UI效果,以满足实际需求。 ### 回答3: 要改变Android TextInputLayout的样式,可以通过以下步骤: 1. 首先,在项目的res文件夹下创建一个新的XML文件,比如命名为custom_text_input_layout.xml。在该文件中,可以自定义TextInputLayout的样式。 2. 在custom_text_input_layout.xml文件中,可以使用XML属性来改变样式。例如,可以修改背景颜色、边框颜色、字体颜色等。可以根据自己的需求进行样式修改。 3. 在布局文件中使用自定义样式的TextInputLayout。找到需要使用的TextInputLayout控件,通过设置style属性将其样式修改为custom_text_input_layout。例如:<com.google.android.material.textfield.TextInputLayout style="@style/CustomTextInputLayout"> 4. 如果还需要修改TextInputEditText(即EditText控件),可以在CustomTextInputLayout的属性中设置相应的样式,例如:app:hintTextAppearance="@style/CustomTextInputEditText" 5. 另外,还可以通过在styles.xml文件中定义样式,再将样式应用到CustomTextInputLayout中。例如,在styles.xml中定义一个样式: <style name="CustomTextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox"> <item name="boxBackgroundMode">filled</item> <item name="boxBackgroundColor">@color/custom_background_color</item> <item name="hintTextColor">@color/custom_hint_text_color</item> <item name="boxStrokeColor">@color/custom_stroke_color</item> </style> 然后,在布局文件中使用该样式:<com.google.android.material.textfield.TextInputLayout style="@style/CustomTextInputLayout"> 通过以上步骤,就可以自定义Android TextInputLayout的样式了。根据自己的需求,可以修改背景颜色、边框颜色、字体颜色等来改变样式
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

峥嵘life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值