java - Android Studio:如何在一个按钮中设置标题和描述?
问题描述
我有ListView
可以添加两个的地方TextView
。
但我需要向一个按钮添加NAME
和。INFO
你可以推荐我什么?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginTop="7.5dp"
android:layout_marginEnd="7dp"
android:layout_marginBottom="7.5dp"
android:background="@drawable/list_background"
android:elevation="5dp"
android:orientation="vertical"
android:paddingBottom="12dp">
<TextView
android:id="@+id/subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:textAllCaps="true"
android:textColor="@color/textColor"
android:textSize="30sp"
tools:text="Name" />
<TextView
android:id="@+id/subject_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="15dp"
android:paddingEnd="5dp"
android:textColor="@color/infoColor"
android:textSize="16sp"
tools:text="Info" />
例如我想要像这个按钮这样的按钮
解决方案
使用 Spanable 字符串。您可以设置大小和样式跨度以更改文本大小并使其变为粗体。
String s= "Hello Everyone";
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
ss1.setSpan(boldSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView tv= (TextView) findViewById(R.id.textview);
tv.setText(ss1);
推荐阅读
- c# - LINQ - 将当前和以前的数据合并到一行
- python - 将多条正文线转换为列表理解
- node.js - Mongoose findById 查询不返回结果。对象始终为空。
- git - 无法连接到存储库:无法创建 http 代理 uri
- python - 如何在 Django 中呈现多个表单
- python - dataframe combine_first does not work as well as fillna
- c# - 展平数据库中实体上的复杂对象
- java - 需要通过section id从HTML中获取href
- angular - 如何在angular2+中使用螺栓而不是http请求
- angular - 变量在打字稿中自动更改