public class ExtendedCheckBoxListView extends LinearLayout { private TextView mText; private CheckBox mCheckBox; public ExtendedCheckBoxListView(Context context, ExtendedCheckBox aCheckBoxifiedText) { super(context); … mText.setFocusable(false); mText.setFocusableInTouchMode(false); mCheckBox.setFocusable(false); mCheckBox.setFocusableInTouchMode(false); … } }
/** * Work around some 'features' of TextView and URLSpans. i.e. vanilla URLSpans do not react to * touch so we replace them with our own {@link TouchableUrlSpan} * & {@link LinkTouchMovementMethod} to fix this. * <p/> * Setting a custom MovementMethod on a TextView also alters touch handling (see * TextView#fixFocusableAndClickableSettings) so we need to correct this. */ public static void setTextWithNiceLinks(TextView textView, CharSequence input) { textView.setText(input); textView.setMovementMethod(LinkTouchMovementMethod.getInstance()); textView.setFocusable(false); textView.setClickable(false); textView.setLongClickable(false); }
Dialog createDialog () { textView = createView(context); textView.setOnKeyListener(this); FrameLayout.LayoutParams textBoxLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM); textView.setLayoutParams(textBoxLayoutParams); textView.setFocusable(true); textView.setFocusableInTouchMode(true); textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI); final FrameLayout layout = new FrameLayout(context); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); layout.setLayoutParams(layoutParams); layout.addView(textView); layout.setOnTouchListener(this); dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); dialog.setContentView(layout); return dialog; }
/** * set SearchView OnClickListener * * @param v * @param listener */ public static void setSearchViewOnClickListener(View v, OnClickListener listener) { if (v instanceof ViewGroup) { ViewGroup group = (ViewGroup) v; int count = group.getChildCount(); for (int i = 0; i < count; i++) { View child = group.getChildAt(i); if (child instanceof LinearLayout || child instanceof RelativeLayout) { setSearchViewOnClickListener(child, listener); } if (child instanceof TextView) { TextView text = (TextView) child; text.setFocusable(false); } child.setOnClickListener(listener); } } }
Dialog createDialog () { textView = createView(context); textView.setOnKeyListener(this); FrameLayout.LayoutParams textBoxLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM); textView.setLayoutParams(textBoxLayoutParams); textView.setFocusable(true); textView.setFocusableInTouchMode(true); textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI); final FrameLayout layout = new FrameLayout(context); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); layout.setLayoutParams(layoutParams); layout.addView(textView); layout.setOnTouchListener(this); dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); dialog.setContentView(layout); return dialog; }
void setLinks(TextView tv, String text) { String[] linkPatterns = { "([Hh][tT][tT][pP][sS]?:\\/\\/[^ ,'\">\\]\\)]*[^\\. ,'\">\\]\\)])", "#[\\w]+", "@[\\w]+" }; for (String str : linkPatterns) { Pattern pattern = Pattern.compile(str); Matcher matcher = pattern.matcher(tv.getText()); while (matcher.find()) { int x = matcher.start(); int y = matcher.end(); final android.text.SpannableString f = new android.text.SpannableString( tv.getText()); InternalURLSpan span = new InternalURLSpan(); span.text = text.substring(x, y); f.setSpan(span, x, y, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(f); // tv.setOnLongClickListener(span.l); } } tv.setLinkTextColor(Color.BLUE); tv.setLinksClickable(true); tv.setMovementMethod(LinkMovementMethod.getInstance()); tv.setFocusable(false); }
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START); textView.setClickable(false); textView.setFocusable(false); textView.setFocusableInTouchMode(false); textView.setTextColor(android.graphics.Color.WHITE);
public MyViewHolder(View view) { super(view); textView = (TextView) view.findViewById(R.id.item); textView.setFocusable(true); } }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { mContext = parent.getContext(); TextView view = new TextView(mContext); view.setLayoutParams(new ViewGroup.LayoutParams(SETTINGS_ITEM_WIDTH, SETTINGS_ITEM_HEIGHT)); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setBackgroundColor(Color.DKGRAY); view.setTextColor(Color.WHITE); view.setGravity(Gravity.CENTER); return new ViewHolder(view); }
/** * 设置左侧文字是否可以点击 */ public void setLeftTextClickable(boolean isClickable) { mTvLeft.setClickable(isClickable); mTvLeft.setFocusable(isClickable); }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { TextView view = new TextView(parent.getContext()); view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT)); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setBackgroundColor(getResources().getColor(R.color.default_background)); view.setTextColor(Color.WHITE); view.setGravity(Gravity.CENTER); return new ViewHolder(view); }
/** * 设置右侧文字是否可以点击 */ public void setRightTextClickable(boolean isClickable) { mTvRight.setClickable(isClickable); mTvRight.setFocusable(isClickable); }
// make the title scroll! // find the title TextView TextView title = (TextView) findViewById(android.R.id.title); // set the ellipsize mode to MARQUEE and make it scroll only once title.setEllipsize(TruncateAt.MARQUEE); title.setMarqueeRepeatLimit(1); // in order to start strolling, it has to be focusable and focused title.setFocusable(true); title.setFocusableInTouchMode(true); title.requestFocus();
TextView text2 = (TextView) findViewById(R.id.textView1); Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new OnClickListener(){ public void onClick(View v) { text2.setFocusable(true); text2.requestFocus(); } });
// make the title scroll! // find the title TextView TextView title = (TextView) findViewById(android.R.id.title); // set the ellipsize mode to MARQUEE and make it scroll only once title.setEllipsize(TruncateAt.MARQUEE); title.setMarqueeRepeatLimit(1); // in order to start strolling, it has to be focusable and focused title.setFocusable(true); title.setFocusableInTouchMode(true); title.requestFocus();
/** * 倒计时 */ private void doCountdown() { countdownNum = COUNT_MAX; txtSendCode.setEnabled(false); txtSendCode.setFocusable(false); timer.start(); } @Override
TextView textView=(TextView)findViewById(R.id.text_test); textView .setEllipsize(TextUtils.TruncateAt.MARQUEE); textView .setSingleLine(true); textView .setMarqueeRepeatLimit(-1); textView.setFocusableInTouchMode(true); textView.setFocusable(true);
private void initView() { TextView tvMain = findView(R.id.tv_main); tvMain.setFocusable(false); // 将随机获得的图像追加到EditText控件的最后 tvMain.append(parseHtml()); tvMain.append(" 测试文本 "); tvMain.append(parseHtml()); tvMain.append(" 这表情还不错吧? "); tvMain.append(parseHtml()); tvMain.append(" 随机添加表情 "); tvMain.append(parseHtml()); }
/** * Sets the given `TextView` to be read-only or read-and-write * * @param view a `TextView` or one of its subclasses * @param readOnly whether the view should be read-only or not */ public static void setReadOnly(final TextView view, final boolean readOnly) { view.setFocusable(!readOnly); view.setFocusableInTouchMode(!readOnly); view.setClickable(!readOnly); view.setLongClickable(!readOnly); view.setCursorVisible(!readOnly); }
this.setTitle("my title!"); ((TextView)v.findViewById(R.id.title)).setText(this.getTitle()); TextView title = ((TextView)v.findViewById(R.id.title)); title.setEllipsize(TextUtils.TruncateAt.MARQUEE); title.setMarqueeRepeatLimit(1); // in order to start strolling, it has to be focusable and focused title.setFocusable(true); title.setSingleLine(true); title.setFocusableInTouchMode(true); title.requestFocus();