Android TextView 与 EditText 的区别与使用,Android通用流行框架大全

本文介绍了Android中TextView和EditText的区别与使用,详细解析了TextView的常见属性,包括文字、尺寸、颜色、样式、链接识别等。此外,文章还提及了作者的Android学习路线与建议,分享了Android开发的学习资源和进阶方向。
摘要由CSDN通过智能技术生成

  • TextView 继承 View,作用就是在界面上显示文本(类似于 iOS 中的 UILabel),同时它还是 EditTextButton 两个 UI 组件类的父类。

  • 另外 Android 关闭了它的文字编辑功能,如果想编辑内容,则可以使用 EditText

二、TextView


  • TextView 常用属性

| 属性 | 含义 |

| — | — |

| id | 为 TextView 设置一个组件 id,根据 id,可以在 Java 代码中通过findViewById() 的方法获取到该对象,然后进行相关属性的设置。 |

| layout_width | 组件宽度 |

| layout_height | 组件高度 |

| text | 设置显示的文本内容,通常是把字符串写到 res/values/strings.xml 文件中, 然后通过 @string/xxx 取得对应的字符串内容。 |

| textSize | 字体大小,单位一般是用 sp。 |

| textColor | 设置字体颜色,同上,通过 res/values/colors.xml 资源来引用(使用:@color/xxx) |

| textStyle | 设置字体风格,三个可选值: normal(无效果)、bold(加粗)、 italic(斜体)。 |

| autoLink | 识别链接类型:webemailphonemapnone

很抱歉,我是一名语言模型AI,无法提供图形界面的设计。但是我可以为您提供相关的代码实现参考,您可以根据自己的需求进行修改和调整。 XML布局文件代码示例: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <ImageView android:id="@+id/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" /> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名" android:padding="10dp" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:padding="10dp" android:inputType="textPassword" /> <CheckBox android:id="@+id/remember_me" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住密码" /> <Button android:id="@+id/login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" /> <TextView android:id="@+id/register" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册新用户" android:gravity="center" android:textColor="@android:color/holo_blue_bright" /> <Toast android:id="@+id/toast" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录成功" /> </LinearLayout> ``` Java代码示例: ``` public class LoginActivity extends AppCompatActivity { private EditText mUsername; private EditText mPassword; private CheckBox mRememberMe; private Button mLogin; private TextView mRegister; private Toast mToast; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mUsername = findViewById(R.id.username); mPassword = findViewById(R.id.password); mRememberMe = findViewById(R.id.remember_me); mLogin = findViewById(R.id.login); mRegister = findViewById(R.id.register); mToast = findViewById(R.id.toast); mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String username = mUsername.getText().toString(); String password = mPassword.getText().toString(); boolean rememberMe = mRememberMe.isChecked(); // TODO: 实现登录逻辑 mToast.show(); } }); mRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO: 跳转到注册界面 } }); } } ``` 注意:上述代码仅为示例,您需要根据自己的需求进行修改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值