本文整理了Java中android.widget.TextView.getFilters()
方法的一些代码示例,展示了TextView.getFilters()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getFilters()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getFilters
暂无
代码示例来源:origin: robolectric/robolectric
@Test
public void canSetAndGetInputFilters() throws Exception {
final InputFilter[] expectedFilters = new InputFilter[]{new InputFilter.LengthFilter(1)};
textView.setFilters(expectedFilters);
assertThat(textView.getFilters()).isSameAs(expectedFilters);
}
代码示例来源:origin: stackoverflow.com
import java.lang.reflect.Field;
// [...]
public static int getMaxLengthForTextView(TextView textView)
{
int maxLength = -1;
for (InputFilter filter : textView.getFilters()) {
if (filter instanceof InputFilter.LengthFilter) {
try {
Field maxLengthField = filter.getClass().getDeclaredField("mMax");
maxLengthField.setAccessible(true);
if (maxLengthField.isAccessible()) {
maxLength = maxLengthField.getInt(filter);
}
} catch (IllegalAccessException e) {
Log.w(filter.getClass().getName(), e);
} catch (IllegalArgumentException e) {
Log.w(filter.getClass().getName(), e);
} catch (NoSuchFieldException e) {
Log.w(filter.getClass().getName(), e);
} // if an Exception is thrown, Log it and return -1
}
}
return maxLength;
}
代码示例来源:origin: stackoverflow.com
public class PlainEditText extends EditText {
public PlainEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
addFilter(this, new PlainTextInputFilter());
}
private void addFilter(TextView textView, InputFilter filter) {
InputFilter[] filters = textView.getFilters();
InputFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1);
newFilters[filters.length] = filter;
textView.setFilters(newFilters);
}
private static class PlainTextInputFilter implements InputFilter {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
int dstart, int dend) {
return stripRichText(source, start, end);
}
private CharSequence stripRichText(CharSequence str, int start, int end) {
// ...
}
}
}
代码示例来源:origin: jbruchanov/AnUitor
e.printStackTrace();
data.put("FiltersCount", tv.getFilters() != null ? tv.getFilters().length : 0);
data.put("FreezesText", tv.getFreezesText());
data.put("Hint", String.valueOf(tv.getHint()));
内容来源于网络,如有侵权,请联系作者删除!