简体   繁体   English

在android上的TextView中添加标签

[英]Add label inside a TextView on android

是否可以在EditText添加TextView

With your edit, I'm assuming what you're looking for is EditText 's android:hint attribute. 通过编辑,我假设您正在寻找的是EditTextandroid:hint属性。 This will add a slightly transparent caption inside the EditText which will disappear upon pressing it. 这将在EditText中添加一个稍微透明的标题,按下它后它将消失。

I'm guessing you want a TextView label and an edit box TextEdit ... 我猜你想要一个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);

You can find the API here: 你可以在这里找到API:

http://developer.android.com/reference/android/widget/EditText.html 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/TextView.html

http://developer.android.com/reference/android/widget/LinearLayout.html http://developer.android.com/reference/android/widget/LinearLayout.html

You can also add those as xml files. 您还可以将它们添加为xml文件。 There's a very simple tutorial (that you could easily adapt to this) here: http://developer.android.com/guide/tutorials/views/hello-linearlayout.html 这里有一个非常简单的教程(你可以很容易地适应这个): http//developer.android.com/guide/tutorials/views/hello-linearlayout.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM