Android:以编程方式创建TextView

Bel*_*lgi 1 android android-layout

如何创建TextView(使用Java代码,而不是xml)layout_width=fill_parent

TextView应该是可编辑的.

Hir*_*ral 6

如果我不理解错误的问题,你需要以EditText编程方式创建.然后,尝试使用:

EditText et=new EditText(context);
et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)

编辑:

导入LayoutParams:

import android.view.ViewGroup.LayoutParams;
Run Code Online (Sandbox Code Playgroud)