setOnFocusChangeListener ( )源码实例Demo

android.widget.TextView#setOnFocusChangeListener ( )源码实例Demo

下面列出了android.widget.TextView#setOnFocusChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: green_android   文件: TwoFactorActivity.java
private TextView setupDetailsView(final int inputType, final String hint) {
    setView(R.layout.activity_two_factor_3_provide_details, R.id.activity_two_factor_3_provide_details);

    final TextView detailsText = UI.find(this, R.id.details);
    detailsText.setInputType(inputType);
    detailsText.setHint(hint);

    final InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    // Show the keyboard; this workaround is needed due to Android bugs
    detailsText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                detailsText.postDelayed(() -> {
                    detailsText.requestFocus();
                    imm.showSoftInput(detailsText, 0);
                }, 100);
            }
        }
    });
    return detailsText;
}
 
源代码2 项目: Trebuchet   文件: Hotseat.java
void resetLayout() {
    mContent.removeAllViewsInLayout();

    // Add the Apps button
    Context context = getContext();

    LayoutInflater inflater = LayoutInflater.from(context);
    TextView allAppsButton = (TextView)
            inflater.inflate(R.layout.all_apps_button, mContent, false);
    Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

    mLauncher.resizeIconDrawable(d);
    allAppsButton.setCompoundDrawables(null, d, null, null);

    allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
    allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
    if (mLauncher != null) {
        mLauncher.setAllAppsButton(allAppsButton);
        allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
        allAppsButton.setOnClickListener(mLauncher);
        allAppsButton.setOnLongClickListener(mLauncher);
        allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
    }

    // Note: We do this to ensure that the hotseat is always laid out in the orientation of
    // the hotseat in order regardless of which orientation they were added
    int x = getCellXFromOrder(mAllAppsButtonRank);
    int y = getCellYFromOrder(mAllAppsButtonRank);
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1);
    lp.canReorder = false;
    mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
}
 
源代码3 项目: LB-Launcher   文件: Hotseat.java
void resetLayout() {
    mContent.removeAllViewsInLayout();

    if (!LauncherAppState.isDisableAllApps()) {
        // Add the Apps button
        Context context = getContext();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        Utilities.resizeIconDrawable(d);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(mAllAppsButtonRank);
        int y = getCellYFromOrder(mAllAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
源代码4 项目: bither-android   文件: CurrencyAmountView.java
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    final Context context = getContext();

    textView = (TextView) getChildAt(0);
    textView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    textView.setHintTextColor(lessSignificantColor);
    textView.setHorizontalFadingEdgeEnabled(true);
    textView.setSingleLine();
    textView.setCompoundDrawablePadding(UIUtil.dip2pix(2));
    setHint(0);
    setValidateAmount(textView instanceof EditText);
    textView.addTextChangedListener(textViewListener);
    textView.setOnFocusChangeListener(textViewListener);
    textView.setOnEditorActionListener(textViewListener);

    contextButton = new View(context) {
        @Override
        protected void onMeasure(final int wMeasureSpec, final int hMeasureSpec) {
            setMeasuredDimension(textView.getCompoundPaddingRight(),
                    textView.getMeasuredHeight());
        }
    };
    final LayoutParams chooseViewParams = new LayoutParams(ViewGroup.LayoutParams
            .WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    chooseViewParams.gravity = Gravity.RIGHT;
    contextButton.setLayoutParams(chooseViewParams);
    this.addView(contextButton);

    updateAppearance();
}
 
源代码5 项目: zidoorecorder   文件: PipService.java
/**
 * 初始化控件
 */
private void initView()
{
	mVPip = LayoutInflater.from(getApplicationContext()).inflate(R.layout.view_pip, null);
	View rlPip = (RelativeLayout) mVPip.findViewById(R.id.rl_pip);
	mFmPip = (FrameLayout) rlPip.findViewById(R.id.fm_pip);
	mLnFrameBg = (LinearLayout) rlPip.findViewById(R.id.ln_bg);
	mPgbLoading = (ProgressBar) mFmPip.findViewById(R.id.pgb_loading);
	mRlFrame = (RelativeLayout) mFmPip.findViewById(R.id.rl_frame);
	mTvNoSingle = (TextView) mFmPip.findViewById(R.id.tv_no_single);

	mRlController = (RelativeLayout) mVPip.findViewById(R.id.rl_control);
	mLnController = (LinearLayout) mRlController.findViewById(R.id.ln_controller);
	mLnScale = (LinearLayout) mRlController.findViewById(R.id.ln_scale);
	mLnAudio = (LinearLayout) mRlController.findViewById(R.id.ln_audio);
	mImgSwitch = (ImageView) mLnAudio.findViewById(R.id.img_switch);
	mTvReminds = (TextView) mRlController.findViewById(R.id.tv_reminds);

	mSfPip = (SurfaceView) mFmPip.findViewById(R.id.sf_pip);
	SurfaceHolder holder = mSfPip.getHolder();
	holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	holder.addCallback(this);

	View move = mLnController.findViewById(R.id.tv_move);
	mTvScale = (TextView) mLnController.findViewById(R.id.tv_scale);
	mTvAudio = (TextView) mLnController.findViewById(R.id.tv_audio);
	View exit = mLnController.findViewById(R.id.tv_exit);
	View audioSwitch = mLnAudio.findViewById(R.id.rl_audio);

	mScales = new TextView[4];
	mScales[0] = mLnScale.findViewById(R.id.tv_scale_0);
	mScales[1] = mLnScale.findViewById(R.id.tv_scale_1);
	mScales[2] = mLnScale.findViewById(R.id.tv_scale_2);
	mScales[3] = mLnScale.findViewById(R.id.tv_scale_3);

	for (int i = 0; i < mScales.length; i++)
	{
		View v = mScales[i];
		v.setTag(i);
		v.setOnClickListener(this);
		v.setOnKeyListener(this);
		v.setOnFocusChangeListener(this);
	}
	mScales[mScaleMode].setSelected(true);

	move.setOnClickListener(this);
	mTvScale.setOnClickListener(this);
	mTvAudio.setOnClickListener(this);
	exit.setOnClickListener(this);
	audioSwitch.setOnClickListener(this);

	move.setOnFocusChangeListener(this);
	mTvScale.setOnFocusChangeListener(this);
	mTvAudio.setOnFocusChangeListener(this);
	exit.setOnFocusChangeListener(this);
	audioSwitch.setOnFocusChangeListener(this);

	move.setOnKeyListener(this);
	mTvScale.setOnKeyListener(this);
	mTvAudio.setOnKeyListener(this);
	exit.setOnKeyListener(this);
	audioSwitch.setOnKeyListener(this);
	mFmPip.setOnKeyListener(this);

	adjustPipFrame(mWindowType.x, mWindowType.y, mWindowType.width, mWindowType.height);

	WindowManager.LayoutParams params = new WindowManager.LayoutParams();
	params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
	params.format = PixelFormat.RGBA_8888; // 设置图片格式,效果为背景透明
	params.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
	params.width = WindowManager.LayoutParams.MATCH_PARENT;
	params.height = WindowManager.LayoutParams.MATCH_PARENT;

	((WindowManager) getSystemService(WINDOW_SERVICE)).addView(mVPip, params);
	move.requestFocus();
}
 
源代码6 项目: ResearchStack   文件: DateQuestionBody.java
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    View view = inflater.inflate(R.layout.rsb_item_date_view, parent, false);

    TextView title = (TextView) view.findViewById(R.id.label);
    if (viewType == VIEW_TYPE_COMPACT) {
        title.setText(step.getTitle());
    } else {
        title.setVisibility(View.GONE);
    }

    TextView textView = (TextView) view.findViewById(R.id.value);
    textView.setSingleLine(true);
    if (step.getPlaceholder() != null) {
        textView.setHint(step.getPlaceholder());
    } else {
        if (format.getStyle() == AnswerFormat.DateAnswerStyle.Date) {
            textView.setHint(R.string.rsb_hint_step_body_date);
        } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.TimeOfDay) {
            textView.setHint(R.string.rsb_hint_step_body_time);
        } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.DateAndTime) {
            textView.setHint(R.string.rsb_hint_step_body_datetime);
        }
    }

    if (result.getResult() != null) {
        textView.setText(createFormattedResult());
    }

    textView.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus) {
            showDialog(textView);
        }
    });

    textView.setOnClickListener(v -> {
        if (v.isFocused()) {
            showDialog(textView);
        }
    });

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
源代码7 项目: VCL-Android   文件: AdvOptionsDialog.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_advanced_options, container, false);
    getDialog().setCancelable(true);
    getDialog().setCanceledOnTouchOutside(true);


    mPlaybackSpeed = (TextView) root.findViewById(R.id.playback_speed);
    mPlaybackSpeed.setOnFocusChangeListener(mFocusListener);
    mPlaybackSpeed.setOnClickListener(this);
    mPlaybackSpeed.setOnLongClickListener(this);

    mSleep = (TextView) root.findViewById(R.id.sleep);
    mSleep.setOnClickListener(this);
    mSleep.setOnFocusChangeListener(mFocusListener);

    mJumpTitle = (TextView) root.findViewById(R.id.jump_title);
    mJumpTitle.setOnClickListener(this);

    if (mMode == MODE_VIDEO) {
        mPlayAsAudio = (ImageView) root.findViewById(R.id.play_as_audio_icon);
        mPlayAsAudio.setOnClickListener(this);

        mChaptersTitle = (TextView) root.findViewById(R.id.jump_chapter_title);
        mChaptersTitle.setOnFocusChangeListener(mFocusListener);
        mChaptersTitle.setOnClickListener(this);

        mAudioDelay = (TextView) root.findViewById(R.id.audio_delay);
        mAudioDelay.setOnFocusChangeListener(mFocusListener);
        mAudioDelay.setOnClickListener(this);

        mSpuDelay = (TextView) root.findViewById(R.id.spu_delay);
        mSpuDelay.setOnFocusChangeListener(mFocusListener);
        mSpuDelay.setOnClickListener(this);
    } else {
        root.findViewById(R.id.audio_delay).setVisibility(View.GONE);
        root.findViewById(R.id.spu_delay).setVisibility(View.GONE);
        root.findViewById(R.id.jump_chapter_title).setVisibility(View.GONE);
        root.findViewById(R.id.play_as_audio_icon).setVisibility(View.GONE);
    }

    if (mMode == MODE_AUDIO){
        mEqualizer = (TextView) root.findViewById(R.id.opt_equalizer);
        mEqualizer.setOnClickListener(this);
    } else
        root.findViewById(R.id.opt_equalizer).setVisibility(View.GONE);

    mTextColor = mSleep.getCurrentTextColor();

    if (getDialog() != null) {
        int dialogWidth = getResources().getDimensionPixelSize(mMode == MODE_VIDEO ?
                R.dimen.adv_options_video_width:
                R.dimen.adv_options_music_width);
        int dialogHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
        getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
        getDialog().getWindow().setBackgroundDrawableResource(Util.getResourceFromAttribute(getActivity(), R.attr.rounded_bg));
    }
    return root;
}
 
@Override
protected void afterLayoutInflated(Context context, AttributeSet attrs, int defStyle) {
    super.afterLayoutInflated(context, attrs, defStyle);

    // Load custom attributes
    final int drawableRightId;
    final int drawableLeftId;
    final int drawablePadding;
    final int inputWidgetTextAppearance;
    final int inputWidgetTextColor;
    final float inputWidgetTextSize;

    if (attrs == null) {
        inputWidgetTextAppearance = -1;
        inputWidgetTextColor = 0xaa000000;
        inputWidgetTextSize = getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize);
        drawableLeftId = getDefaultDrawableLeftResId();
        drawableRightId = getDefaultDrawableRightResId();
        drawablePadding = 0;
    } else {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingLabelTextViewBase, defStyle, 0);
        drawableRightId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableRight, getDefaultDrawableRightResId());
        drawableLeftId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableLeft, getDefaultDrawableLeftResId());
        drawablePadding = a.getDimensionPixelSize(R.styleable.FloatingLabelTextViewBase_android_drawablePadding, 0);
        inputWidgetTextAppearance = a.getResourceId(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextAppearance, -1);
        inputWidgetTextColor = a.getColor(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextColor, 0xaa000000);
        inputWidgetTextSize = a.getDimension(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextSize, getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize));
        a.recycle();
    }

    final TextView inputWidget = getInputWidget();
    inputWidget.setCompoundDrawablesWithIntrinsicBounds(drawableLeftId, 0, drawableRightId, 0);
    inputWidget.setCompoundDrawablePadding(drawablePadding);
    if (inputWidgetTextAppearance != -1) {
        inputWidget.setTextAppearance(getContext(), inputWidgetTextAppearance);
    }
    inputWidget.setTextColor(inputWidgetTextColor);
    inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
    inputWidget.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (!isFloatOnFocusEnabled()) return;

            if (hasFocus) {
                floatLabel();
            } else {
                if (getInputWidget().getText().length() == 0) {
                    anchorLabel();
                }
            }
        }
    });
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类
 同类方法