我在文件 simple_txt.xml
TextView
模板
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textSize="18sp" >
</TextView>
在一些代码中,我需要从这个模板创建一个 TextView
,类似于:
TextView txt = new TextView(this);
txt.setLayout(R.layout.simple_txt);//???
然后用它做点什么(setText
等)。如何创建这样的 TextView
?
最佳答案
TextView txt = (TextView) View.inflate(this, R.layout.simple_txt, null);
关于android - 从模板 XML 文件创建 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10129953/