【问题标题】:how to give color to the application title string in android如何为android中的应用程序标题字符串赋予颜色
【发布时间】:2015-03-09 16:11:01
【问题描述】:

我想为我的应用程序中的应用程序标题字符串赋予 rgb 颜色 我这样声明的资源文件中的字符串,

<string name="app_name">MyApplication</string>

并用它来像这样在清单文件中设置标题,

<activity
        android:name=".MainActivity"
        android:screenOrientation="portrait" 
        android:theme="@style/MyTheme"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"> 

我想为 MyApplication 字词赋予不同的颜色, rgb(201,89,51) 分别代表 My 和 rgb(74,137,174)

我该怎么做?

【问题讨论】:

  • 什么?你不能这样做
  • This 可能会对您有所帮助。 最好和最简单的方法是在顶部使用带有彩色文本的 TextView(使用 Html.fromHtml)并使用 FullScreenActivity。
  • 还有this

标签: android string android-resources


【解决方案1】:

试试这个

 getActionBar().setTitle(Html.fromHtml("<font color='#ff0000'>My</font><font color='#ff00ff'>Application</font>"));

如果您使用的是 appcompact:

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ff0000'>My</font><font color='#ff00ff'>Application</font>"));

【讨论】:

  • 成功了,非常感谢。来了解一下在android代码中使用HTML,第一次使用
【解决方案2】:

你试过Html.fromHtml(String s) 吗?输出为您提供 HTML 文本样式。一个例子:

String styledText=Html.fromHtml("<font color="#123456">My</font> <font color="#654321">App</font>");

然后设置:

Window w = getWindow();
w.setTitle(styledText);

getSupportActionBar().setTitle(styledText);
//getActionBar().setTitle(styledText);

【讨论】:

    猜你喜欢
    • 2012-02-17
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多