【问题标题】:custom text style with two color具有两种颜色的自定义文本样式
【发布时间】:2019-03-17 16:15:33
【问题描述】:

我想知道可以像这样设置文本样式:

注意:我正在使用shadow,但它对我来说似乎没有用。我想得到如上图所示的两色文本。

这是我的代码:

<com.example.fabulous.comic.CustomTXT
    android:textColor="@color/white"
    android:shadowColor="@color/blacke"
    android:layout_margin="2dp"
    android:id="@+id/txt"
    android:text="hellow"
    android:layout_width="match_parent"/>
    android:layout_height="wrap_content"/>

【问题讨论】:

  • 为您的文本应用自定义字体
  • 快速修复 :使用看起来像这样的自定义字体。
  • @erfan 检查我的答案。

标签: java android android-studio colors background-color


【解决方案1】:

是的,您可以创建这样的文本,请在此处查看我的previous 详细答案。

将文本颜色设置为white,将轮廓颜色设置为black.

【讨论】:

  • 既然可以使用字体,为什么还要创建另一个视图?
  • 是的,您可以使用字体,但您无法控制它们的属性,例如轮廓宽度、颜色与内部颜色相同。
  • @erfan 通过对勾表示更多的爱,并在两个帖子中投票。
【解决方案2】:

您为什么不选择具有自定义颜色的自定义字体? 这个link 可能会帮助您自定义字体。

【讨论】:

    【解决方案3】:

    在 TextView 中使用阴影应该可以实现轮廓效果:

    android:shadowColor="#000000"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:shadowRadius="1.6"
    android:text="CCC"
    android:textAllCaps="true"
    android:textColor="@android:color/white"
    

    您还可以使用WhatTheFont 等网络服务来查找任何图片中使用的警察。我用你的图片找到了最接近的匹配并得到了这个答案:

    警察是Minutia Outline,你可以find it here

    我不确定这是否是您所追求的解决方案,但使用这个警察会得到您所拥有的照片。

    如果您不想使用字体,您可以简单地使用一些 CSS 来设置文本样式,在 Android 中为 webView to use html/css,如下所示:

    .strokeme
    {
        color: white;
        text-shadow:
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000;
        font-size: 250%;
    }
    <div class="strokeme">
        Is this what you were looking for?
    </div>

    【讨论】:

    • 我的荣幸。如果我的回答有帮助,请点赞。谢谢。
    【解决方案4】:

    试试这个

     <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:textColor="@color/white"
    android:textSize="20sp"
    android:shadowColor="@color/black" 
    android:shadowRadius="2"/>
    

    您可以根据需要增加半径并根据需要着色

    您也可以尝试使用字体.....

    使用了谷歌的 Montserrat.ttp 下载,并且您使用了更多字体.. 随心所欲

        String fontPath = "fonts/mont.ttf";
        Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
        btn_reload.setTypeface(tf);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 2013-03-10
      • 1970-01-01
      • 2018-04-05
      相关资源
      最近更新 更多