导航:首页 > 操作系统 > androidtextview图标

androidtextview图标

发布时间:2022-08-26 05:34:54

‘壹’ android中TextView在界面显示的时候,我想在键盘显示的上方加两个按钮,一个是确定,一个是取消.

那个不是TextView 是EditText ,你只要把EditText放在Button上面就行了 代码如下:
粘进去运行就行了 activity随便写个就行 记得配manifest~~~
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<EditText android:id="@+id/et" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_above="@id/add" />
<Button android:text="ok" android:id="@+id/add"
android:layout_alignParentBottom="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:text="cancle" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/add" />
</RelativeLayout>

‘贰’ android 如何在textview最后一个字后边追加一个ImageView图标

textview的配置项里有个属性,android:drawableEnd,设了就可以。你可以去看下官方文档,有好几个属性。

‘叁’ 如何在Android中为TextView动态设置drawableLeft等

只需要代码设置setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom); 这个方法即可,如果说drawableLeft为null,即没有对应的图标

‘肆’ 如何在 Android 应用中使用 FontAwesome 图标

FontAwesome 可以节省许多时间,原因如下:

首先,你不需要担心不同手机上的屏幕分辨率问题。如果你使用png图片,你需要在包里面对每个图标至少包含四种不同的版本。不仅如此,在某些超清屏幕上,你的图标可能会出现颗粒感。这显然是要避免的。但如果使用FontAwesome,你只需包含一个"TTF”文件。
其次,你可以依赖于当今最丰富的免费图标集之一。而且因为其在web上被广泛的使用,现在用户已经习惯了FontAwesome的风格。你不必再浪费时间去寻找漂亮的丰富的可以免费商用的图标集合,我并不是说不存在这样的图标集,因为确实存在,但是非常稀少。
1. FontAwesome 的工作原理
我们先花点时间来了解一下FontAwesome 的工作原理。FontAwesome 图标集背后的思想非常简单,图标被视为字符(character)。你可以能已经注意到一些奇怪的字符被作为文本对待,你可以轻易的拷贝 β 字符或者 ∑ 字符。你甚至可以在普通的文本编辑框中这样做。还可以改变它们的大小和颜色。这是因为浏览器 - 以及文本编辑框 - 把这些字符视为文本。
FontAwesome 通过包含广泛的图标扩展了这一概念。你可以把它比喻成用图标指定的不能打出的Unicode字符。
FontAwesome
看一眼 FontAwesome's cheatsheet 就知道我在说什么了。你选择列表中的一个图标,记下它的Unicode的字符,在TextView中使用它告诉安卓使用FontAwesome字体来渲染。
2. 导入字体文件
让我们来看一个例子。下载和导入FontAwesome 的TrueType 文件到项目。你可以从 GitHub上下载FontAwesome 的assets。
当你下载了FontAwesome之后,你会发现里面包含了一些文件和文件夹。大部分都是对web项目有用的。我们只对位于fonts目录的 fontawesome-webfont.ttf感兴趣。
在你的安卓项目中,导航到 app > src > main。 main 目录应该包含了一个叫 assets的文件夹。如果没有就创建一个。在assets 文件夹中创建另一个fonts文件夹,并把fontawesome-webfont.ttf 添加到这个文件夹。
主义 fonts 文件夹并不是必须的。你可以直接把FontAwesome 的字体文件放在 assets 目录,但是把相同类型的文件放在专门的目录里面比较方便。只要FontAwesome 字体在assets 或者子目录之下就行。
3. 创建一个帮助类
现在你已经成功的把FontAwesome 字体文件包含在了自己的安卓项目里,是时候使用它了。我们会创建一个帮助类来让事情变得简单点。这个类要使用到android.graphics.Typeface。Typeface类指定typeface 以及一个字体的特征。它用于指明text在绘制(以及测量)的时候该如何显示。
创建一个新的名叫FontManager的java类:

1
2
3
4
5
6
7
8
9
10

public class FontManager {

public static final String ROOT = "fonts/",
FONTAWESOME = ROOT + "fontawesome-webfont.ttf";

public static Typeface getTypeface(Context context, String font) {
return Typeface.createFromAsset(context.getAssets(), font);
}

}

如果你想在项目中使用其他的字体,把字体放在helper 类里面就可以了。类似于:

1

yourTextView.setTypeface(FontManager.getTypeface(FontManager.YOURFONT));

我们需要做的就这么多,但是我们可以做的更好。使用上面的方法的话,我们需要为每个想当成图标来使用的TextView创建一个变量。但作为一个程序员,我们都很懒,对吧?
图标一般都是包含在一个ViewGroup,比如一个RelativeLayout或者LinearLayout中。我们可以写一个方法,爬遍指定xml parent 并且递归的覆盖每个TextView的字体。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

public class FontManager {

// ...

public static void markAsIconContainer(View v, Typeface typeface) {
if (v instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {
View child = vg.getChildAt(i);
markAsIconContainer(child);
}
} else if (v instanceof TextView) {
((TextView) v).setTypeface(typeface);
}
}

}

假设你的布局文件是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/icons_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />

</LinearLayout>

要把这三个TextView标记为图标,我们重写onCreate方法,并添加如下代码片段:

1
2

Typeface iconFont = FontManager.getTypeface(getApplicationContext(), FontManager.FONTAWESOME);
FontManager.markAsIconContainer(findViewById(R.id.icons_container), iconFont);

4. 使用你想要的图标
现在轮到有意思的部分了。访问 FontAwesome的GitHub页面 并浏览所给的图标。选择三个你喜欢的。我准备选择三个chart图标,分别是 area chart icon, pie chart icon, 以及 line chart icon。
在你的项目中,进入 values 文件夹并创建一个新的文件:icons.xml。这个文件将被作为字典使用,它将把Unicode 字符和相应的图标用可读的名字匹配起来。这意味着我们需要为每个图标创建一个入口。

1
2
3
4
5

<resources>
<string name="fa_icon_areachart"></string>
<string name="fa_icon_piechart"></string>
<string name="fa_icon_linechart"></string>
</resources>

你可以在FontAwesome cheatsheet或者图标的 详情页面 找到你感兴趣图标的代码。
下一步就是在布局的TextView里面引用这些字符串。这是最终的样子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_areachart" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_piechart" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_linechart" />

如果你打开Android Studio的布局编辑器,你会看到它无法渲染这些图标。这是不正常的。编译并启动应用,你又会发现图标是正常渲染了的。

看起啦很小是吧?改变图标的大小很简单,你只需改变textSize属性就是了。改变图标的颜色也一样简单,编辑textColor属性就是了。

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textSize="45sp"
android:textColor="#9b59b6"
android:text="@string/fa_icon_areachart" />

‘伍’ android中如何在TextView中显示文字的同时加上笑脸一样的图标

使用 SpannableString 这个类,可以防止图片和添加文本,然后放置在textView中就可以了

‘陆’ Android 的Textview控件

对android不是很熟悉。
我的理解是:这个TextView是在XML里面告诉android这是一个textview控件。
然后android:text是告诉android这个textview上面显示的内容的。这个textview就只有这么一个属性,因此只能设置一次。如果是在代码里面修改的话,应该是随便你怎么改都没有问题。

‘柒’ android自定义view怎么画textview

自定义view绘制的时候,都是通过画笔/画布,使用一些画线/画圆的,通过设置画笔的颜色/字体/文字大小,画布的背景等等来绘制想要的图形.如果需要监听点击事件,也可以添加ontouch事件.

阅读全文

与androidtextview图标相关的资料

热点内容
广东加密货币 浏览:216
利用python批量查询系统 浏览:495
什么app看左右脸 浏览:302
台湾小公主s解压密码 浏览:568
易语言锁机软件源码 浏览:156
迅雷下载完成无法解压 浏览:592
硬盘分区命令图解 浏览:447
当前云服务器如何关闭 浏览:78
mac下python在哪 浏览:641
广东惠州DNS服务器地址 浏览:357
编译影片时软件渲染错误 浏览:625
流星蝴蝶剑解压失败 浏览:294
如何确认方舟编译器 浏览:664
奶粉源箱源码什么意思 浏览:178
台州程序员兼职一般去哪些网站 浏览:408
旧版本怎么下载到新的安卓 浏览:972
flash个人网站源码下载 浏览:724
javasocketbyte 浏览:270
素描基础教程pdf 浏览:542
香港商报pdf版 浏览:428