更改Android TextView子弹颜色

时间:2016-10-13 05:58:40

标签: android xml textview

我在XML代码中的TextView中使用了bullet,我不知道为什么在TextView颜色为白色时,某些设备的颜色为红色。这可能是因为设备默认主题。我怎样才能让它变白。

活动主题:

 <style name="AppThemeOnBoarding" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
</style>

我的XML代码:

<TextView
   android:gravity="center"
   android:padding="20dp"
   style="@style/TextView_shadow"
   android:layout_centerInParent="true"
   android:alpha="0.9"
   android:textSize="13sp"
   android:textColor="#ffffff"
   android:text="i Verbindung am besten mit: \n✔ ABC\n✔ XYZ"
   android:id="@+id/fitbit_connectiondesc"
   android:layout_below="@id/fitbit_label"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"/>

Result

6 个答案:

答案 0 :(得分:1)

check this image

 tv.setText(Html.fromHtml("i Verbindung am besten mit:" + "<font color=\"#ffffff\">" +"<br>✔ ABC <br>✔ XYZ"+ "</font><br><br>"));

// xml like

<TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

答案 1 :(得分:0)

以编程方式使用此设置白色

mTextView.setTextColor(Color.parseColor("#ffffff"));

答案 2 :(得分:0)

请参阅TextView中的Activity,并以html格式设置文字,如

TextView fitbitTV = (TextView) findViewById(R.id.fitbit_connectiondesc);
String content = "<font color='#FFFFFF'>i Verbindung am besten mit: \n✔ ABC\n✔ XYZ</font>";
fitbitTV.setText(Html.fromHtml(content));

答案 3 :(得分:0)

使用如下字体创建html字符串。

Last_Errno: 1060
Last_Error: Error 'Duplicate column name 'feed_order'' on query. Default database: 'example.com'. Query: 'ALTER TABLE wp_gf_addon_feed ADD COLUMN feed_order mediumint(8) unsigned not null default 0'

Last_SQL_Errno: 1060
               Last_SQL_Error: Error 'Duplicate column name 'feed_order'' on query. Default database: 'example.com'. Query: 'ALTER TABLE wp_gf_addon_feed ADD COLUMN feed_order mediumint(8) unsigned not null default 0'
  Replicate_Ignore_Server_Ids:

这是示例代码。

使用&#39; android:textColor&#39; 文字样式。

答案 4 :(得分:0)

在风格中使用

<item name="android:textColor">@color/AppThemeOnBoarding</item>

<style name="AppThemeOnBoarding" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
 <item name="android:textColor">@color/AppThemeOnBoarding</item>
</style>

答案 5 :(得分:0)

我找到了另一种方法来实现这一目标。我正在使用Spannable设置&#34; bullet tick&#34;在TextView之间的图像,子弹的替代品。 这很完美。

String string = "i Verbindung am besten mit: \n ABC \n XYZ";
String abc = "ABC";
String xyz = "XYZ";

SpannableString spannableString = new SpannableString(string);

int startPosition1 = string.indexOf(abc);
int startPosition2 = string.indexOf(xyz);

Bitmap bullettick = BitmapFactory.decodeResource( getResources(), R.drawable.tick_bullet);

spannableString.setSpan( new ImageSpan( bullettick ), startPosition1-2, startPosition1, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
spannableString.setSpan( new ImageSpan( bullettick ), startPosition2-2, startPosition2, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
textview.setText(spannableString);
textview.setMovementMethod(LinkMovementMethod.getInstance());
相关问题