3

我正在为一所大学构建一个应用程序。根据需要,我为每个段落添加了单独的 TextView 段落。有没有办法让我可以合并段落。这只是我对这是否可能的想法?这是我处理的代码片段。

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry." />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="14dp"
android:inputType="numberSigned"
android:text="+91 12 12345678" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:inputType="phone"
android:text="+91 12 12345678" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:autoLink="email"
android:inputType="textEmailAddress"
android:text="admissions@abc.edu" />

在我的代码中,我想将两个电话号码和电子邮件 ID 组合在一个 TextView 中。可能吗?

4

4 回答 4

5

试试这个方法,希望这能帮助你解决你的问题。

主要的.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

我的活动.java

public class MyActivity extends Activity{

    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        textView = (TextView) findViewById(R.id.textView);
        String htmlText = "<p> +91 12 12345678 </p> <p> +91 12 12345678 </p> <p> admissions@abc.edu </p>";
        textView.setText(Html.fromHtml(htmlText));
    }
}
于 2014-07-18T09:13:06.507 回答
1

我不相信有一种方法可以在 XML 中执行此操作,只能使用多个文本视图......您可以通过 html 转换以编程方式执行此操作。

此外,您应该从每个中删除android:inputType="",它们用于 EditText,而不是 TextView。

于 2014-07-18T09:09:00.603 回答
0
  1. 在 xml 文件中突出显示要成为段落的文本,然后按alt+enter

  2. 选择“提取为字符串”选项并按回车键。

  3. 然后,文本将自动成为写入 strings.xml 文件最后一行的字符串,该文件位于任何 Android Studio 原生项目的 res/values 文件夹中。

  4. 现在通过在要将句子文本分成段落的位置之间添加\n来编辑文本。

    完成,简单,不客气

于 2020-08-29T07:17:08.200 回答
-1

在我看来,最好使用一个 TextView 并给它一个android:src="@string/your_string"属性。

然后进入res->values->strings并添加:

<string name="your_string">Everything you want to display write it here</string>    

希望我有所帮助。

于 2015-02-03T10:30:06.337 回答