导航:首页 > 操作系统 > androidtextview文字颜色

androidtextview文字颜色

发布时间:2022-06-01 00:49:13

① 安卓开发:如何静态和动态设置textView的文本和背景色彩,如何填初学不知填啥.要详细

静态就是在可视化的Graphical Layout内的属性内填
textView1.TextColor(文本色)
textView1.Background(背景色)
中填 @android就会自动弹出所有定义的色彩值
如 @android:color/holo_blue_bright
动态就是程序中设定色彩
import android.graphics.Color;

textView1.setTextColor(Color.RED);
textView1.setBackgroundColor(Color.RED);

② android TextView怎么设置个别字体颜色并换行

由于你没有自己定义颜色,默认为灰色。 有两种方式设置: 1:在java类中 TextView tv = new TextView(this); tv.setTextColor(Color.RED);利用这种方式设置字体颜色。 2:在xml文件中 在你的TextView中有textColor属性,给属性值为RGB格式就行了.

③ Android编程问题:改变TextView中指定字体颜色

TextView htmlFormateTextView = (TextView)findViewById(R.id.testTextView);

String source = "这只是一个测试,测试<u>下划线</u>、<i>斜体字</i>、<font color='blue'>蓝色字</font>的格式";

htmlFormateTextView.setText(Html.fromHtml(source));

④ android TextView怎么设置个别字体颜色并换行

1、TextView 设置个别字体颜色

TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml("你的内容:<fontcolor=red>要设置的内容</font>"));

2、TextView 设置字体换行

TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText("你的内容");

3、TextView 设置个别字体颜色并换行

TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml("内容:<br/><fontcolor=red>juapk.com</font>"));

或者可以用SpannableString 设置字体颜色

StringXM="asd";
SpannableStringmsp=newSpannableString("测试"+XM+"更换当前号码将从手机发送一条普通短信进行验证");
2msp.setSpan(newForegroundColorSpan(Color.BLUE),2,XM.length()+2,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

⑤ android,在线性布局中如何改变里面所有textView的文字颜色呢要用到函数吗

1、自定义TextView并改变字体颜色,把xml布局里面的全替换成你这个;
2、在代码界面,通过查找子View来遍历,如果子view是TextView则改字体颜色

⑥ android 中的textview中 设置字的颜色,失效只有第一个可以显示出来颜色,其他的都是系统默认的

其他是否处于不可用状态,察看一下代码中是否设置了setEnabled(false)

⑦ Android 中 textview点击改变文字颜色 并在点击另一个textView时变回原来的颜色

private TextView mTextDisp; mTextDisp = (TextView) findViewById(R.id.textDisp_mian); mTextDisp.setTextColor(R.color.red);(使用color.xml文件中的颜色值) 这样写是怎么也变不成红色的,而且程序不报错,不知道朋友们有没有试过。而且debug所走的分支也是正确的。 我就单独写了一个Demo来测试,结果还是灰显。 有的朋友要说,是不是red的颜色值写错了。不是,color中的颜色值配置对着呢。 其实,答案很简单,就错在mTextDisp.setTextColor(R.color.red);这行代码上。 首先,在xml中不要写默认的字体颜色值,即android:textColor="xxx" 其次,在activity中mTextDisp.setTextColor(context.getResources().getColor(R.color.red));(使用color.xml文件中的颜色值) 这样就OK了。或者直接使用Color类中的值:mTextDisp.setTextColor(Color.RED);(使用系统自带的颜色类Color类中的颜色值)。

⑧ android listview的item被点击时,如何改变item里面的textview的文字颜色

parent.getChildAt(position).

这个方法应该是可行的。

View v=parent.getChildAt(position);
v.setTextColor();

如果不行,先这样

for(int i=0;i<parent.getCount();i++){
View w=parent.getChildAt(i);
w.setTextColor(别的color);
}



View v=parent.getChildAt(position);
v.setTextColor();

这样试试吧。

⑨ android 如何设置TextView中字体在不同状态下的颜色

TextView的字体设置方法:
1、直接通过配置文件设置
2、在Activity类中进行设置

第一种方式很简单,用于静态或初始文字颜色的设置,方法如下:

main.xml

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout>
color.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>
drawable.xml

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="dark">#000000</drawable>
<drawable name="red">#FF0000</drawable>
</resources>
strings.xml

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">地址:http://yahaitt.javaeye.com</string>
<string name="app_name">丫梨的笔记本</string>
</resources>

上面将资源部分分成了3个部分,目的是为了清晰,当然你也可以只建一个xml文件放在res目录下,而且文件名称可以随便命名。

注意两个地方:
1、main.xml的TextView标签中:
android:textColor="@color/red"
2、color.xml中:
<color name="red">#FF0000</color>

@color指获取资源文件中(所有res目录下的xml文件)的<color>标签
/red指在标签下找其name值为red的内容,此时其值为#FF0000

因此,这里我们还可以这样做:
android:textColor="@drawable/red"

@drawable指获取资源文件中<drawable>标签
/red指在标签下找其name值为red的内容

以此类推,相信你也就知道了如果是在strings.xml中该怎么做了。

下面看看第二种方式:在Activity类中进行设置

1、先将main.xml改成如下,即去掉android:textColor="@color/red":

Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
/>
</LinearLayout>
2、修改Activity的onCreate方法,这里我的Activity是Study03_01,原始代码如下:

Java代码
package yahaitt.study03_01;

import android.app.Activity;
import android.os.Bundle;

public class Study03_01 extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

第一步:获得文本控件TextView,取名为tv

第二步:通过TextView的setTextColor方法进行文本颜色的设置,这里可以有3种方式进行设置:

第1种:tv.setTextColor(android.graphics.Color.RED);//系统自带的颜色类

第2种:tv.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色,注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表示。

第3种:tv.setTextColor(this.getResources().getColor(R.color.red));//通过获得资源文件进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red,当然前提是需要在相应的配置文件里做相应的配置,如:
<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>

详细的代码如下:
Java代码
package yahaitt.study03_01;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

public class Study03_01 extends Activity {

private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tv = (TextView)this.findViewById(R.id.tv01);

// tv.setTextColor(Color.RED);

// tv.setTextColor(0xff000000);

⑩ android studio 怎么设置textview的字体颜色为黑色

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="西堤牛排" android:id="@+id/top" android:textSize="40dip"(大小) android:textColor="#000000"(颜色) />

阅读全文

与androidtextview文字颜色相关的资料

热点内容
自己购买云主服务器推荐 浏览:419
个人所得税java 浏览:761
多余的服务器滑道还有什么用 浏览:189
pdf劈开合并 浏览:28
不能修改的pdf 浏览:752
同城公众源码 浏览:488
一个服务器2个端口怎么映射 浏览:297
java字符串ascii码 浏览:78
台湾云服务器怎么租服务器 浏览:475
旅游手机网站源码 浏览:332
android关联表 浏览:945
安卓导航无声音怎么维修 浏览:332
app怎么装视频 浏览:430
安卓系统下的软件怎么移到桌面 浏览:96
windows拷贝到linux 浏览:772
mdr软件解压和别人不一样 浏览:904
单片机串行通信有什么好处 浏览:340
游戏开发程序员书籍 浏览:860
pdf中图片修改 浏览:288
汇编编译后 浏览:491