是否可以在EditText
中添加一个TextView
?
是否可以在EditText
中添加一个TextView
?
根据您的编辑,我理解您要找的是 EditText
的 android:hint
属性。这将在 EditText 内部添加一个略微透明的标题,该标题在按下时会消失。
TextView
标签和一个编辑框 TextEdit
...LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
TextView label = new TextView(this);
EditText edit = new EditText(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
label.setText("My Label");
edit.setText ("My Edit");
ll.addView(label, layoutParams);
ll.addView(edit, layoutParams);
setContentView(ll);
http://developer.android.com/reference/android/widget/EditText.html
http://developer.android.com/reference/android/widget/TextView.html
http://developer.android.com/reference/android/widget/LinearLayout.html
你也可以将它们添加为xml文件。这里有一个非常简单的教程(你可以轻松地适应它):http://developer.android.com/guide/tutorials/views/hello-linearlayout.html