Java Code Examples for android.widget.TextView#setFocusable()

The following examples show how to use android.widget.TextView#setFocusable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtils.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: DescriptionFragment.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_description, container, false);

    mTitleView = (TextView) rootView.findViewById(R.id.title);
    mSummaryView = (TextView) rootView.findViewById(R.id.summary);

    if (Utils.isTv(getActivity())) {
        mSummaryView.setFocusable(true);
    } else {
        mTitleView.setTextIsSelectable(true);
        mSummaryView.setTextIsSelectable(true);
    }

    mSummaryView.setSelected(true);
    mSummaryView.setMovementMethod(LinkMovementMethod.getInstance());

    mTitle = getArguments().getCharSequence("title");
    mSummary = getArguments().getCharSequence("summary");

    refresh();
    return rootView;
}
 
Example 3
Source File: TextPopup.java    From mappwidget with Apache License 2.0 6 votes vote down vote up
public TextPopup(Context context, ViewGroup parentView) 
{
    super(context, parentView);
    
    text = new TextView(context);
    
    text.setPadding((int)(PADDING_LEFT * dipScaleFactor),
                    (int)(PADDING_TOP * dipScaleFactor),
                    (int)(PADDING_RIGHT  * dipScaleFactor), 
                    (int)(PADDING_BOTTOM * dipScaleFactor));
    
    text.setBackgroundResource(R.drawable.map_description_background);
    text.setTextSize(DEF_TEXT_SIZE);
    text.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
    text.setMaxEms(MAX_EMS);
    text.setTextColor(Color.WHITE);
    
    container.addView(text);

    text.setFocusable(true);
    text.setClickable(true);
}
 
Example 4
Source File: CourseView.java    From ClassSchedule with Apache License 2.0 6 votes vote down vote up
@NonNull
private TextView getCourseTextView(int h, int w) {
    TextView tv = new TextView(getContext());
    LayoutParams params = new LayoutParams(w, h);
    tv.setLayoutParams(params);

    tv.setTextColor(mTextColor);
    tv.setLineSpacing(-2, 1);
    tv.setPadding(mTextLRPadding, mTextTBPadding, mTextLRPadding, mTextTBPadding);
    tv.setTextColor(mTextColor);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
    tv.setFocusable(true);
    tv.setClickable(true);
    //bold
    TextPaint tp = tv.getPaint();
    tp.setFakeBoldText(true);
    return tv;
}
 
Example 5
Source File: ViewCore.java    From TitleBar with Apache License 2.0 6 votes vote down vote up
static TextView newTitleView(Context context) {
    TextView titleView = new TextView(context);
    titleView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1));
    titleView.setGravity(Gravity.CENTER);
    titleView.setFocusable(true);
    titleView.setSingleLine();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE_1_1) {
        // 给标题设置跑马灯效果(仅在标题过长的时候才会显示)
        titleView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        // 设置跑马灯的循环次数
        titleView.setMarqueeRepeatLimit(-1);
        // 设置跑马灯之后需要设置选中才能有效果
        titleView.setSelected(true);
    } else {
        titleView.setEllipsize(TextUtils.TruncateAt.END);
    }
    return titleView;
}
 
Example 6
Source File: GuideActivity.java    From ViewPagerTabIndicator with Artistic License 2.0 6 votes vote down vote up
private void addTextTab(final int position, String title) {

        TextView tab = new TextView(this);
        tab.setText(title);
        tab.setTextSize(25);
        tab.setFocusable(true);
        tab.setGravity(Gravity.CENTER);
        tab.setSingleLine();
        tab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewPager.setCurrentItem(position);
            }
        });


        tab.setPadding(tabPadding, 0, tabPadding, 0);

        tabsContainer.addView(tab, position);
    }
 
Example 7
Source File: Shadowsocks.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
/**
 * init toolbar
 */
private void initToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    // non-translatable logo
    toolbar.setTitle("shadowsocks R");
    toolbar.setTitleTextAppearance(toolbar.getContext(), R.style.Toolbar_Logo);
    try {
        Field field = Toolbar.class.getDeclaredField("mTitleTextView");
        field.setAccessible(true);
        TextView title = (TextView) field.get(toolbar);
        title.setFocusable(true);
        title.setGravity(0x10);
        title.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Shadowsocks.this, ProfileManagerActivity.class));
            }
        });
        TypedArray typedArray = obtainStyledAttributes(new int[]{R.attr.selectableItemBackgroundBorderless});
        title.setBackgroundResource(typedArray.getResourceId(0, 0));
        typedArray.recycle();
        Typeface tf = Typefaces.get(this, "fonts/Iceland.ttf");
        if (tf != null) {
            title.setTypeface(tf);
        }
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: StringPresenter.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView textView = new TextView(parent.getContext());
    textView.setFocusable(true);
    textView.setFocusableInTouchMode(true);
    textView.setBackground(
            parent.getContext().getResources().getDrawable(R.drawable.background_cone));
    return new ViewHolder(textView);
}
 
Example 9
Source File: MainFragment.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: TVDemoFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
    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);
}
 
Example 11
Source File: TextItemPresenter.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(ITEM_WIDTH, ITEM_HEIGHT));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    view.setTextSize(32);
    return new ViewHolder(view);
}
 
Example 12
Source File: ViewCore.java    From TitleBar with Apache License 2.0 5 votes vote down vote up
static TextView newRightView(Context context) {
    TextView rightView = new TextView(context);
    rightView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
    rightView.setGravity(Gravity.CENTER_VERTICAL);
    rightView.setFocusable(true);
    rightView.setClickable(true);
    rightView.setSingleLine();
    rightView.setEllipsize(TextUtils.TruncateAt.END);
    return rightView;
}
 
Example 13
Source File: ViewCore.java    From TitleBar with Apache License 2.0 5 votes vote down vote up
static TextView newLeftView(Context context) {
    TextView leftView = new TextView(context);
    leftView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
    leftView.setGravity(Gravity.CENTER_VERTICAL);
    leftView.setFocusable(true);
    leftView.setClickable(true);
    leftView.setSingleLine();
    leftView.setEllipsize(TextUtils.TruncateAt.END);
    return leftView;
}
 
Example 14
Source File: TVDemoFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
    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);
}
 
Example 15
Source File: MainFragment.java    From alltv with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {

    TextView view = new TextView(parent.getContext());

    view.setLayoutParams(new ViewGroup.LayoutParams(getResources().getInteger(R.integer.GRID_ITEM_WIDTH), getResources().getInteger(R.integer.GRID_ITEM_HEIGHT)));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);

    return new ViewHolder(view);
}
 
Example 16
Source File: ChildrenAdapter.java    From EpisodeListView with Apache License 2.0 4 votes vote down vote up
public MyViewHolder(View view) {
    super(view);
    textView = (TextView) view.findViewById(R.id.item);
    textView.setFocusable(true);
}
 
Example 17
Source File: FloatLabelLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 18
Source File: FloatLabelLayout.java    From delion with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 19
Source File: FloatLabelLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 20
Source File: HtmlUtils.java    From android-proguards with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}