【问题标题】:Change the underline of android textfields in Titanium Alloy更改钛合金中android文本字段的下划线
【发布时间】:2016-12-17 13:14:46
【问题描述】:

我正在尝试使用自定义主题更改 Titanium Alloy 中 Android 文本字段的下划线颜色,但由于某种原因,它没有选择我的新颜色。

我在project/app/platform/android/res/values/awesome_theme.xml下创建了一个主题,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="awesome" parent="@style/Theme.AppCompat">
        <item name="colorControlNormal">#ff0000</item>
        <item name="colorControlActivated">#00ff00</item>
        <item name="colorControlHighlight">#0000ff</item>
    </style>
</resources>

我已经更改了我的tiapp.xml 文件以使用新主题:

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:theme="@style/awesome"/>
</android>

我已经清理了项目,但是当我重建项目时,文本字段仍然显示为默认的蓝色下划线。

我在这里做错了什么?

【问题讨论】:

    标签: android titanium titanium-alloy


    【解决方案1】:

    您必须使用不同的背景图片,转到您的 XML "awesome_theme.xml" 并添加自定义 EditText 样式

     <style name="EditTextCustomHolo" parent="android:Widget.EditText">
           <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
           <item name="android:textColor">#ffffff</item>
        </style>
    

    使用图像drawble文件-->apptheme_edit_text_holo_lightEditText样式中,您可以使用具有笔划的可绘制资源文件,使用那个或这个笔划,

     <?xml version="1.0" encoding="utf-8"?>
     <item>
        <shape android:shape="rectangle">
            <stroke
                android:width="1dp"
                android:color="@color/white"/>
        </shape>
    </item>
    

    然后只需在您的EditText 中执行此操作:

    <EditText
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       style="@style/EditTextCustomHolo"/>
    

    您可以更改EditText 的下划线颜色,在 awesome_theme.xml 中指定它。在您的样式下添加以下标签Theme.AppCompat

    <item name="android:textColorSecondary">@color/primary_text_color</item>
    

    注意:android:textColorSecondary是用来判断ActionBar中后退箭头和DrawerLayout汉堡图标的颜色,太soo小心了

    【讨论】:

    • "转到您的 XML "styles.xml""。我的项目中没有该文件?
    • res>values>styles 如果你没有一个使用你添加主题的那个,请看这里-> carlos-r-mendoza.github.io/img/…
    • 这个答案实际上是否基于我的代码。它读起来就像它是从其他地方复制的一样,至少可以说让我很困惑。你能解释一下为什么我所拥有的东西不起作用吗?
    • 因为你没有 @color/primary_text_color 在你的 标签中,这将为你完成这项工作,我解释了问题也使用它,如果你只想要答案,我认为我浪费了我的时间,这里我提到了 3 种不同的方法来实现这一点
    • 当我将android:textColorSecondary 添加到我的 awesome_theme.xml 文件中时,它不再编译。 “[错误]:无法打包应用程序:[错误]:[错误]:无法生成拆分''的资源表[错误]:路径/到/项目/build\android\res\values\awesome_theme.xml:7 :错误:错误:找不到与给定名称匹配的资源(在'android:textColorSecondary',值为'@color/primary_text_color')。“
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 2018-04-29
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    相关资源
    最近更新 更多