Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在活动中给出段落?_Android_Android Activity_Parser Combinators_Paragraphs - Fatal编程技术网

Android 如何在活动中给出段落?

Android 如何在活动中给出段落?,android,android-activity,parser-combinators,paragraphs,Android,Android Activity,Parser Combinators,Paragraphs,我正在为一所大学开发一个应用程序。根据需要,我为每个段落添加了单独的文本视图。有没有办法让我把段落组合起来。我只是在想这是否可能?下面是我编写的代码片段 <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPostalAddress" android:text="Lorem I

我正在为一所大学开发一个应用程序。根据需要,我为每个段落添加了单独的文本视图。有没有办法让我把段落组合起来。我只是在想这是否可能?下面是我编写的代码片段

<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组合在一个文本视图中。有可能吗?

我认为在XML中没有办法做到这一点,只能使用多个文本视图。。。您可以通过html转换以编程方式完成


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

试试这种方法,希望这能帮助您解决问题。

main.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>

MyActivity.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));
    }
}
公共类MyActivity扩展活动{
私有文本视图文本视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView=(textView)findViewById(R.id.textView);
字符串htmlText=“+91 12 12345678

+91 12 12345678

admissions@abc.edu

”; setText(Html.fromHtml(htmlText)); } }
在我看来,最好使用一个文本视图,并给它一个android:src=“@string/your_string”属性

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

<string name="your_string">Everything you want to display write it here</string>    
要显示的所有内容都在此处写入
希望我能帮忙

  • 突出显示要成为xml文件中段落的文本,然后按alt+enter键

  • 选择选项“提取为字符串”并按enter

  • 然后,文本将自动成为写入 res/values中的strings.xml文件的最后一行 任何Android studio本机项目的文件夹

  • 现在,通过在想要编辑文本的位置之间添加\n来编辑文本 把句子正文分成一段

    完成了,很简单,不客气


  • 为什么不将
    WebView
    TextView
    Html
    格式化文本一起使用?它支持段落和更多标记。那么它就不需要为每个段落单独设置文本视图了。@user370305,“WebView”,好的,我会使用。但是如何处理Html格式的文本呢?请引导我,我是android的新手。谢谢。它很好用。但是,我们缺少了一致性。我该怎么做?如果我有很长的段落呢?我也能这样做吗?.java文件会不会变得更笨拙?如果您了解更多关于html代码的知识,您可以轻松处理更多问题。谢谢。我接受你的答案--android:inputType=“”这对段落没有帮助,所以它实际上更多的是一个评论而不是一个答案。请改进答案,直接回答与段落有关的问题。。你所说的只是关于制作字符串的评论。。它不能解决段落问题。。非常感谢。