[英]Add label inside a TextView on android
是否可以在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);
你可以在這里找到API:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.