【问题标题】:How to set codes in html page?如何在html页面中设置代码?
【发布时间】:2014-01-28 06:55:41
【问题描述】:

我是 html 新手,我正在制作一个 html 页面,我想在其中显示一些代码,但它没有像我们在记事本中写的那样显示正确的方式。所以,我必须写每一行
或任何其他解决方案。假设这是代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.liste);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Setup the list view
    final ListView prestListView = (ListView) findViewById(R.id.list);
    final prestationAdapterEco prestationAdapterEco = new prestationAdapterEco(this, R.layout.prestation);

    prestListView.setAdapter(prestationAdapterEco);

    // Populate the list, through the adapter
    for(final prestationEco entry : getPrestations()) {
        prestationAdapterEco.add(entry);
    }
    prestListView.setClickable(true);
    prestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            Object o = prestListView.getItemAtPosition(position);
            String str=(String)o;//As you are using Default String Adapter
            Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT).show();
        }
    });
}

我只想在这样的 html 页面上显示它。请帮忙..谢谢

【问题讨论】:

    标签: html


    【解决方案1】:
    <pre><code> code... </code></pre>
    

    这似乎是他们在这里找到的最好方法:<code> vs <pre> vs <samp> for inline and block code snippets

    这也是show a sample of computer code on W3.org的推荐方式。

    【讨论】:

    【解决方案2】:

    我认为您正在寻找 HTML 页面中的代码/语法突出显示。不幸的是,HTML 中没有使用标签的突出显示功能。

    在 HTML 中你可以使用:

    <code>You code goes here..</code>
    

    更多参考:http://www.w3schools.com/tags/tag_code.aspcode标签支持的全局属性列表:http://www.w3schools.com/tags/ref_standardattributes.asp

    但是,您可以使用一些 javascript 来启用 HTML 中的语法高亮显示。

    您可以查看此主题:“Syntax highlighting code with Javascript”了解更多信息。

    【讨论】:

      猜你喜欢
      • 2014-10-07
      • 1970-01-01
      • 2017-08-04
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 2017-06-07
      • 1970-01-01
      相关资源
      最近更新 更多