2015-10-04 30 views

回答

1

我以前没有这样做,但是像这样的东西应该可以工作: 让您的类实现TextWatcher接口。

当您创建的TextView,添加textView.addTextChangedListener(this);

然后加:

public void afterTextChanged(Editable s) { 
    if(textView.getLineCount() >= 4) { 
     ToggleButton showMoreToggle = (ToggleButton) findViewById(R.id.showMoreToggle); 
     showMoreToggle.setVisibility(View.VISIBLE); 
    } 
} 
public void onTextChanged(CharSequence s,int start, int before, int count) {} 
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 

然后做一个切换按钮在XML,并添加android:click="onClick"android:visibility="gone"。然后在你的活动代码放:

public void onClick(View v) { 
    ToggleButton tb = (ToggleButton) v; 
    textView.setMaxLines(tb.isChecked() ? 10 : 4); 
} 
+0

感谢geokavel为输入时,setLines是刚刚设置的行数显示在TextView的,它被丢弃行的TextView的休息 – antroid

+0

好,我加了现在有更多的东西,让我知道它是怎么回事。 – geokavel