简体   繁体   English

如何在 android 中以编程方式更改自定义 UI 元素的特定 XML 属性

[英]How to change specific XML attribute of custom UI element programmatically in android

I am using a custom UI component in my project which has it's own few attributes.我在我的项目中使用了一个自定义 UI 组件,它有自己的几个属性。 I want to change a specific one using a function when it is clicked.我想在单击时使用 function 更改特定的。 I don't know how to access it though, I am fairly new in this department.我不知道如何访问它,我是这个部门的新手。

<com.chinodev.androidneomorphframelayout.NeomorphFrameLayout
                    android:id="@+id/btnsystem"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    app:neomorph_background_color="@color/appBackground"
                    app:neomorph_corner_radius="10dp"
                    app:neomorph_elevation="4dp"
                    app:neomorph_highlight_color="#ffffff"
                    app:neomorph_shadow_color="#CDCDCD"
                    app:neomorph_view_type="rectangular">

here say I want to change the app:neomorph_elevation using onclick function how can I do that?这里说我想使用 onclick function 更改app:neomorph_elevation neomorph_elevation 我该怎么做?

In NeomorphFrameLayout you can add a public function changeElevation exNeomorphFrameLayout ,您可以添加公共 function changeElevation ex

 fun changeElevation(elevation :Float){
      neomorph_elevation = elevation
    }

and can use in onClickListener like并且可以在 onClickListener 中使用

btnsystem.changeElevation(5f)

As they specified in library that,正如他们在图书馆中指定的那样,

Attributes: neomorph_clickable option set it to true and onClick trigger a function from xml or from setOnClickListener whichever you prefer...属性:neomorph_clickable 选项将其设置为 true 和 onClick 触发 function 从 xml 或从 setOnClickListener 哪个你喜欢...

https://github.com/4inodev/Neomorphic-FrameLayout-Android https://github.com/4inodev/Neomorphic-FrameLayout-Android

android-repository-history安卓存储库历史

History of Android repository XML Android 存储库 XML 的历史

repository2-$N.xml and addons_list-3.xml repository2-$N.xml 和 addons_list-3.xml

Used by sdkmanager command.sdkmanager命令使用。

repository-$N.xml and addons_list-2.xml存储库-$N.xml 和 addons_list-2.xml

Used by android command, which is deprecated and unavailable in the latest Android SDK Tools (since r25.3.0)android命令使用,在最新的 Android SDK 工具(自 r25.3.0 起)中已弃用且不可用

如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在具有特定属性的特定元素上写入XML文档? - How to write to XML document at specific element with specific attribute? 如何在 Android 10 中以编程方式设置自定义主题属性 - How to set custom theme attribute programmatically in Android 10 如何以编程方式更改 android 的值: tint 属性<bitmap xml< div><div id="text_translate"><p> 我是新来的,我需要你的帮助。 请告诉我如何从程序级别访问层列表 xml 结构并从程序级别动态更改 bitmap 的“色调”颜色。</p><pre> &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/bg_peper" android:right="65dp"&gt; &lt;bitmap android:gravity="top|left" android:tint="@color/red" android:src="@drawable/ic_favorite" /&gt; &lt;/item&gt; &lt;item.... &lt;/layer-list&gt;</pre></div></bitmap> - How to programmatically change the value of the android: tint property in <bitmap xml 如何使用lxml更改android xml文件中的属性值,例如“ android:text” - How to change attribute values such as “android:text” in android xml file with lxml 如何以编程方式更改 XML 中的值 - How to change a value in XML programmatically 如何将属性添加到XML元素 - how to add an attribute to an XML element 如何更改字符串中特定文本的字体大小。xml android - How to change the font size of specific text in strings.xml android 如何以编程方式在视图上设置自定义属性 - How to set a custom attribute on a view programmatically 如何以编程方式更改样式属性值? - How to change style attribute value in programmatically? 如何以Java编程方式读取XML元素? - How to read an XML element programmatically in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM