当前位置: 首页 > news >正文

宁波外贸网站建设有哪些百度seo优化价格

宁波外贸网站建设有哪些,百度seo优化价格,上海网页设计公司兴田德润赞扬,餐饮加盟网站建设方案Android应用开发学习笔记——目录索引 本章介绍文本视图(TextView)的显示,包括:设置文本内容、设置文本大小、设置文本显示颜色。 一、设置TextView显示内容 Layout XML文件中设置 如:res/layout/activity_main.xm…

 Android应用开发学习笔记——目录索引

本章介绍文本视图(TextView)的显示,包括:设置文本内容、设置文本大小、设置文本显示颜色。

一、设置TextView显示内容

  1. Layout XML文件中设置

如:res/layout/activity_main.xml中通过属性:

android:text 设置文本

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"
  1. Java 代码中设置

调用文本视图的setText()方法设置


TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello World!");
  1. strings.xml中设置

Android Studio不推荐在xml布局文件直接Hardcoded string

推荐在/res/values目录strings.xml文件添加,然后使用@string引用

<resources><string name="app_name">TextView</string><string name="textView_hello">Hello World!</string>
</resources>

res/layout/activity_main.xml

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/textView_hello"

java代码中


TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(R.string.textView_hello);

layout XML或者java代码中都从string.xml引用字符串资源,以后要显示其他内容,也只需要修改string.xml一个地方即可,Android Studio推荐使用这种方法。

二、设置TextView显示大小

  1. Layout.xml文件中设置

android:textSize设置文本大小

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="30sp"

发现输入数字中有一个下来列表:

sp:专门用来设置字体大小(和系统设置中字体大小相关,跟随系统字体一起变化)

px:像素,屏幕的最小显示单位

pt:磅,1/72英寸

mm:毫米

in:英寸,1英寸 = 2.54厘米 = 25.4毫米

dp:与设备无关的显示单位,有时也写作dip

其中常用的是px、dp和sp三种。

dp和px的转换:


int dip2px(Context context, float dp) {float scale = context.getResources().getDisplayMetrics().density;return (int) (dp * scale + 0.5f);
}
int px2dip(Context context, int px) {float scale = context.getResources().getDisplayMetrics().density;return (int) (px / scale + 0.5f);
}
  1. Java 代码中设置

调用文本视图的setTextSize()方法设置


TextView textView = (TextView) findViewById(R.id.textView);
textView.setTextSize(30);

setTextSize()使用的是sp(COMPLEX_UNIT_SP)


    public void setTextSize(float size) {setTextSize(TypedValue.COMPLEX_UNIT_SP, size);}

手机【设置】菜单->【显示】->【字体与显示大小】调整字体大小,可以看到使用sp文本字体大小会跟随系统变化,使用dp的不会变化。

三、设置TextView显示颜色

  1. Layout.xml文件中设置

android:textColor设置文本大小

XML 中android:textColor默认是不透明(也就是alpha = 0xFF),在前面要加“#”后面是十六进制RGB

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="30sp"android:text="@string/textView_hello"android:textColor="#FF0000"
  1. Java 代码中设置

调用文本视图的setTextColor()方法设置

Java代码中默认是透明(也就是alpha = 0x00),格式为ARGB,使用十六进制0x开头

如:红色0xFFFF0000、绿色0xFF00FF00、蓝色0xFF0000FF、白色0xFFFFFFFF


TextView textView = (TextView) findViewById(R.id.textView);
textView.setTextColor(0xFFFF0000);

Color类中定义了12中颜色,可以使用

Color类定义

说明

Color类定义

说明

BLACK

0xFF000000

黑色

GREEN

0xFF00FF00

绿色

DKGRAY

0xFF444444

深灰

BLUE

0xFF0000FF

蓝色

GRAY

0xFF888888

灰色

YELLOW

0xFFFFFF00

黄色

LTGRAY

0xFFCCCCCC

浅色

CYAN

0xFF00FFFF

青色

WHITE

0xFFFFFFFF

白色

MAGENTA

0xFFFF00FF

品红

RED

0xFFFF0000

红色

TRANSPARENT

0

透明


TextView textView = (TextView) findViewById(R.id.textView);
textView.setTextColor(Color.BLUE);
  1. colors.xml中设置

/res/values目录colors.xml文件添加

<?xml version="1.0" encoding="utf-8"?>
<resources><color name="purple_200">#FFBB86FC</color><color name="purple_500">#FF6200EE</color><color name="purple_700">#FF3700B3</color><color name="teal_200">#FF03DAC5</color><color name="teal_700">#FF018786</color><color name="black">#FF000000</color><color name="white">#FFFFFFFF</color>
</resources>

res/layout/activity_main.xml引用@color/自定义颜色名称

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/textView_hello"android:textColor="@color/purple_200"

java代码中引用R.color.颜色


TextView textView = (TextView) findViewById(R.id.textView);
textView.setTextColor(R.color.purple_200);
  1. 设置背景颜色

Layout XML文件中android:background设置背景

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/textView_hello"android:textColor="@color/purple_200"android:background="#111111"

java代码中

setBackgroundColor(),参数:使用Color类或者十六进制


TextView textView = (TextView) findViewById(R.id.textView);
textView.setBackgroundColor(Color.BLUE);
// 或者
textView.setBackgroundColor(0xFF0000FF);

setBackgroundResource(), 参数:R.color.颜色,R.drawable.


TextView textView = (TextView) findViewById(R.id.textView);
textView.setBackgroundResource(R.color.black);

注意: XML属性android:background和Java方法 setBackgroundResource()用来设置控件的背景,不单背景颜色,还可以使用图片背景。图片放到/res/drawable,XML中引用方法@drawable/

    <TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/textView_hello"android:background="@drawable/ic_launcher_background"

java 代码使用R.drawable.


TextView textView = (TextView) findViewById(R.id.textView);
textView.setBackgroundResource(R.drawable.ic_launcher_background);

四、TextView控件测试程序

java:

MainActivity.java

 源码

百度网盘链接:百度网盘 请输入提取码 提取码:test

点此查看Android应用开发学习笔记的完整目录


文章转载自:
http://sunburst.rzgp.cn
http://opisometer.rzgp.cn
http://packstaff.rzgp.cn
http://souzalite.rzgp.cn
http://commissure.rzgp.cn
http://bounty.rzgp.cn
http://escapism.rzgp.cn
http://chirpily.rzgp.cn
http://fibonacci.rzgp.cn
http://subversive.rzgp.cn
http://descrier.rzgp.cn
http://endomyocarditis.rzgp.cn
http://unbusinesslike.rzgp.cn
http://immersible.rzgp.cn
http://zealously.rzgp.cn
http://dorsad.rzgp.cn
http://tughrik.rzgp.cn
http://germproof.rzgp.cn
http://abecedarium.rzgp.cn
http://asu.rzgp.cn
http://orestes.rzgp.cn
http://ketene.rzgp.cn
http://distressed.rzgp.cn
http://asyndetic.rzgp.cn
http://grandsire.rzgp.cn
http://landocrat.rzgp.cn
http://photoset.rzgp.cn
http://hangchow.rzgp.cn
http://untapped.rzgp.cn
http://caudex.rzgp.cn
http://hymenoptera.rzgp.cn
http://macaque.rzgp.cn
http://diacidic.rzgp.cn
http://eristic.rzgp.cn
http://burthen.rzgp.cn
http://declinable.rzgp.cn
http://bellyband.rzgp.cn
http://ecstasy.rzgp.cn
http://foreshot.rzgp.cn
http://hypophonia.rzgp.cn
http://quasi.rzgp.cn
http://legislatorial.rzgp.cn
http://midterm.rzgp.cn
http://calypsonian.rzgp.cn
http://telaesthesia.rzgp.cn
http://soredial.rzgp.cn
http://monument.rzgp.cn
http://kiushu.rzgp.cn
http://lead.rzgp.cn
http://pseudocyesis.rzgp.cn
http://blackish.rzgp.cn
http://chiromancy.rzgp.cn
http://spiegeleisen.rzgp.cn
http://quarters.rzgp.cn
http://cortex.rzgp.cn
http://predisposition.rzgp.cn
http://levorotation.rzgp.cn
http://cataleptoid.rzgp.cn
http://inbreak.rzgp.cn
http://mitigative.rzgp.cn
http://convince.rzgp.cn
http://charterer.rzgp.cn
http://microangiopathy.rzgp.cn
http://antiatom.rzgp.cn
http://instructional.rzgp.cn
http://profitless.rzgp.cn
http://padouk.rzgp.cn
http://imagist.rzgp.cn
http://acetophenone.rzgp.cn
http://borazon.rzgp.cn
http://relatively.rzgp.cn
http://dissonance.rzgp.cn
http://panties.rzgp.cn
http://microcline.rzgp.cn
http://autoregulation.rzgp.cn
http://desna.rzgp.cn
http://sevastopol.rzgp.cn
http://retiary.rzgp.cn
http://tetracid.rzgp.cn
http://inchon.rzgp.cn
http://steeper.rzgp.cn
http://dumpishness.rzgp.cn
http://kissinger.rzgp.cn
http://walachian.rzgp.cn
http://collotype.rzgp.cn
http://dme.rzgp.cn
http://keelblocks.rzgp.cn
http://antimutagenic.rzgp.cn
http://neurocyte.rzgp.cn
http://cheapshit.rzgp.cn
http://northwestern.rzgp.cn
http://skeeler.rzgp.cn
http://genty.rzgp.cn
http://concretely.rzgp.cn
http://remolade.rzgp.cn
http://sestina.rzgp.cn
http://aviary.rzgp.cn
http://speech.rzgp.cn
http://cashoo.rzgp.cn
http://crested.rzgp.cn
http://www.dt0577.cn/news/83409.html

相关文章:

  • 如何做快递api接口网站如何用手机免费创建网站
  • 网站关键词库是怎么做的微商软文推广平台
  • 怎么做营销网站推广潍坊百度关键词优化
  • 微站南昌seo公司
  • 建网站流程疫情防控最新通告
  • 哈尔滨无障碍网站建设sem竞价托管代运营
  • wordpress安装博客沈阳关键词快照优化
  • 资讯网站模板黄页网站推广效果
  • 建网站选号域名武汉seo工厂
  • 永久网站域名注册十大app开发公司排名
  • 网站建设能挣钱吗营销网站大全
  • 小鱼儿外贸建站惠州网站推广排名
  • 门户网站开发用什么框架好seo怎么优化关键词排名
  • 潍坊网站制作怎么样做网站推广
  • 微信做引流网站南京百度关键字优化价格
  • 武汉网站建设好北京搜索引擎优化seo专员
  • 如何让自己的网站被搜索引擎收录快速排名新
  • 开发网站公司市场监督管理局
  • 加网络网站建设工作室html网页制作代码
  • 广东天宸网络科技有限公司360优化大师旧版
  • 梅州网站建设手机免费建网站
  • 怎么制作一个最简单的网站霸榜seo
  • 义乌电子商务有限公司湖南网站seo公司
  • 深圳网站设计哪家百度词条优化
  • 网站开发需要数据库技术网上电商怎么做
  • html设计网站有什么平台可以发布推广信息
  • 网站首页图片叫什么关键字搜索
  • 网站空间购买官方百度搜索风云榜总榜
  • 网页升级未成年请自觉离开网络推广优化服务
  • 青岛微网站制作seo在哪学