Android Studio:如何在一个按钮中设置标题和描述?

时间:2018-11-30 09:22:46

标签: java android listview button

我有func verifyNumber(_ number: String) -> Bool { let pattern = "^[1-9][0-9]{10}$" // test that the length is correct and it's composed from digits guard number.range(of: pattern, options: .regularExpression) != nil else { return false } // convert characters to numbers let digits: [Int] = number.compactMap { Int(String($0)) } // split digits and check digits let d = Array(digits.prefix(9)) let c = Array(digits.suffix(2)) // calculate check digits let c1 = ((d[0] + d[2] + d[4] + d[6] + d[8]) * 7 - (d[1] + d[3] + d[5] + d[7])) % 10 let c2 = (d.reduce(0, +) + c1) % 10 // validate check digits return c[0] == c1 && c[1] == c2 } ,可以在其中添加两个ListView

但是我需要将TextViewNAME添加到一个按钮。你能推荐我什么?

INFO

例如,我想要这样的按钮button

2 个答案:

答案 0 :(得分:0)

在drawable中创建一个名为border_main的xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="7dp" />
    <solid android:color="#fff" />
    <stroke
        android:width="1dp"
        android:color="@color/white" />
</shape>

并像

一样使用它
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
android:background="@drawable/border_main "
        android:orientation="horizontal"
        android:padding="10dp"
        android:id="@+id/lin"
        android:layout_margin="2dp"
 >-othetr components
</LinearLayout>

答案 1 :(得分:0)

使用可扩展字符串。您可以设置“大小”和“样式跨度”以更改文本大小并使其变粗。

 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);

输出如下 enter image description here