我的目标是隐藏文本并使文本视图在活动中占据空间,我已经通过以下方法将文本设置为不可见:
tv.setVisibility(View.INVISIBLE);
当按钮单击它显示文本时,除了代码的结果外,所有东西都可以正常工作,不仅隐藏文本,还可以隐藏整个文本视图,因为我将文本视图背景设置为可绘制形状,在文本周围形成红色边框,如:
android:background="@drawable/border1"
<TextView
android:id="@+id/introclusion_tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border1"
android:textSize="20sp" />
当开始应用程序时,你只能看到空白处,在点击按钮后会填充文本,但是没有边框(来自形状背景),所以它隐藏了整个文本视图,我需要它只隐藏文本,并在文本设置为不可见时保持文本视图的背景显示。
任何帮助都是非常感谢的,谢谢。
我就是这样做的:
TextView tv11=(TextView)findViewById(R.id.introclusion_tv3);
tv11.setText(Html.fromHtml(getString(R.string.introclusion_one)));
tv11.setVisibility(View.INVISIBLE);
然后,单击“但”并写出正确的密码后,它将文本显示为:
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
EditText password = (EditText) dialog.findViewById(R.id.password);
if( password.getText().toString().length() > 0 ) {
if( password.getText().toString().equals("test")) {
TextView tv11=(TextView)findViewById(R.id.introclusion_tv3);
tv11.setTypeface(FontFactory.getBFantezy(getBaseContext()));
tv11.setText(Html.fromHtml(getString(R.string.introclusion_one)));
tv11.setVisibility(View.VISIBLE);
}
发布于 2013-09-18 23:07:16
你可以做一个简单的技巧:写两个字符串
让我们说,在您的第一和第二段代码中,只需删除以下一行
tv11.setVisibility(View.INVISIBLE);
和
tv11.setVisibility(View.VISIBLE);
所以它将是
TextView tv11=(TextView)findViewById(R.id.introclusion_tv3);
tv11.setText(Html.fromHtml(getString(R.string.introclusion_one)));
然后在第二篇文章中写如下;
if( password.getText().toString().equals("test")) {
TextView tv11=(TextView)findViewById(R.id.introclusion_tv3);
tv11.setTypeface(FontFactory.getBFantezy(getBaseContext()));
tv11.setText(Html.fromHtml(getString(R.string.introclusion_one_appear)));
}
其中第一个字符串将为空。
<string name="introclusion_one">
第二个字符串,您将在其中写入文本。
<string name="introclusion_one_appear">
希望能帮助你。
发布于 2013-09-18 22:08:49
透明文本颜色隐藏文本:
<TextView
android:id="@+id/introclusion_tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border1"
android:textColor="@android:color/transparent"
android:textSize="20sp" />
当您想显示文本时,请使用setTextColor()
方法以编程方式更改文本颜色。
tv11.setTextColor(color);
发布于 2013-09-19 06:36:11
// try this way
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border1">
<TextView
android:id="@+id/introclusion_tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
https://stackoverflow.com/questions/18883099
复制相似问题