Android 仅隐藏文本但不隐藏整个文本视图

Android 仅隐藏文本但不隐藏整个文本视图,android,textview,Android,Textview,我的目标是隐藏文本并保持textview在活动中占据其空间,我已使用以下方法将文本设置为不可见: tv.setVisibility(View.INVISIBLE); 当点击按钮显示文本时,除了我的代码导致隐藏整个textview而不仅仅是文本之外,其他一切都正常工作,因为我将textview背景设置为可绘制形状,在文本周围形成红色边框,如下所示: android:background="@drawable/border1" <TextView android:id="@+i

我的目标是隐藏文本并保持textview在活动中占据其空间,我已使用以下方法将文本设置为不可见:

tv.setVisibility(View.INVISIBLE);
当点击按钮显示文本时,除了我的代码导致隐藏整个textview而不仅仅是文本之外,其他一切都正常工作,因为我将textview背景设置为可绘制形状,在文本周围形成红色边框,如下所示:

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" /> 
   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);
                        }
然后单击but并写入正确的密码后,将显示以下文本:

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" /> 
   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);
                        }

将文本视图中的内容保存为字符串,如下所示:

        String x = (String)tv11.getText();
然后将文本视图设置为空,如下所示:

String x = "";
for(int i = 0; i < x.length(); i++){
x +=" ";
}
tv11.setText(x);

将文本视图中的内容保存为字符串,如下所示:

        String x = (String)tv11.getText();
然后将文本视图设置为空,如下所示:

String x = "";
for(int i = 0; i < x.length(); i++){
x +=" ";
}
tv11.setText(x);

透明文本颜色隐藏文本:

<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" /> 

透明文本颜色隐藏文本:

<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" /> 

你可以做一个简单的把戏:写两个字符串

假设在第一段和第二段代码中删除这一行

 tv11.setVisibility(View.INVISIBLE); 

就这样吧

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">


希望对你有所帮助。

你可以做一个简单的小把戏:写两个字符串

// 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>
假设在第一段和第二段代码中删除这一行

 tv11.setVisibility(View.INVISIBLE); 

就这样吧

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">

希望能对您有所帮助。

//试试这个方法
// 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>
//试试这个方法

这是天才。这是天才。