温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

闪亮亮的文本框效果

发布时间:2020-06-22 20:05:22 来源:网络 阅读:660 作者:wy521angel 栏目:移动开发

    我已经相信有些人我永远不必等……当然这要除了送快递的——昨天买了许多IT书和文学小说。

    大学里课程设计的时候做过数字钟,是用汇编语言写的,感觉那个闪亮的数字界面很好看,下面用代码实现一下那种显示界面。

    主类中没什么东西,就不贴代码了,自定义了一个LedTextView类,设置特殊字体,也很简单:

package com.example.ledtextviewtest;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class LedTextView extends TextView {

	public LedTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		AssetManager assetManager = context.getAssets();
		// 设置某种样式的字体
		Typeface font = Typeface.createFromAsset(assetManager, "digital-7.ttf");
		setTypeface(font);
	}

}

    最主要的是从asset文件夹中获取一种字体的样式,样式文件是下载的,我使用的是“digital-7.ttf”,如图:

闪亮亮的文本框效果

    XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000" >

    <com.example.ledtextviewtest.LedTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="88:88:88"
        android:textColor="#3300ff00"
        android:textSize="80sp" />

    <com.example.ledtextviewtest.LedTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#00ff00"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowRadius="10"
        android:text="09:45:23"
        android:textColor="#00ff00"
        android:textSize="80sp" />

</RelativeLayout>

    有两个自定义的UI控件,其中第一个显示背景,第二个显示当前时间值。其中第一个LedTextView设置浅一些的颜色,第二个LedTextView的阴影和字体颜色设置相同,都是“#00ff00”。

android:shadowDx="0"和android:shadowDy="0"可以改变阴影与文本内容之间的偏移度,“0”则表示不偏移。android:shadowRadius="10"为阴影的半径,设置可以使文本看起来更亮些。

    效果图:

闪亮亮的文本框效果

    我只是写了一个文本的效果,可以把它真正做成一个电子时钟。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI