当前位置: 首页>>代码示例>>Java>>正文


Java TextView.getText方法代码示例

本文整理汇总了Java中android.widget.TextView.getText方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getText方法的具体用法?Java TextView.getText怎么用?Java TextView.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.TextView的用法示例。


在下文中一共展示了TextView.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUnrestrictedLayout

import android.widget.TextView; //导入方法依赖的package包/类
private static Layout createUnrestrictedLayout(@Nonnull TextView view) {
    CharSequence text = view.getText();
    Layout layout = view.getLayout();
    TextPaint paint = layout.getPaint();

    if (SDK_INT >= M) {
        return StaticLayout.Builder
                .obtain(text, 0, text.length(), layout.getPaint(), layout.getWidth())
                .setAlignment(layout.getAlignment())
                .setLineSpacing(view.getLineSpacingExtra(), view.getLineSpacingMultiplier())
                .setIncludePad(view.getIncludeFontPadding())
                .setBreakStrategy(view.getBreakStrategy())
                .setHyphenationFrequency(view.getHyphenationFrequency())
                .build();
    } else {
        return new StaticLayout(
                text,
                paint,
                text.length(),
                layout.getAlignment(),
                view.getLineSpacingMultiplier(),
                view.getLineSpacingExtra(),
                view.getIncludeFontPadding());
    }
}
 
开发者ID:shazam,项目名称:reflow-animator,代码行数:26,代码来源:ReflowTextAnimatorHelper.java

示例2: addGesture

import android.widget.TextView; //导入方法依赖的package包/类
@SuppressWarnings({"UnusedDeclaration"})
public void addGesture(View v) {
    if (mGesture != null) {
        final TextView input = (TextView) findViewById(R.id.gesture_name);
        final CharSequence name = input.getText();
        if (name.length() == 0) {
            input.setError(getString(R.string.error_missing_name));
            return;
        }

        final GestureLibrary store = GestureBuilderActivity.getStore();
        store.addGesture(name.toString(), mGesture);
        store.save();

        setResult(RESULT_OK);

        final String path = new File(Environment.getExternalStorageDirectory(),
                "gestures").getAbsolutePath();
        Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
    } else {
        setResult(RESULT_CANCELED);
    }

    finish();
    
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:27,代码来源:CreateGestureActivity.java

示例3: setThreadName

import android.widget.TextView; //导入方法依赖的package包/类
/**
 *  Setting the thread name in the action bar.
 * */
protected boolean setThreadName(TextView txtName){
    String displayName = thread.displayName();

    if (StringUtils.isBlank(displayName) )
        return false;

    if (txtName.getText() == null || !displayName.equals(txtName.getText().toString()))
    {
        // Set the title of the screen, This is used for the label in the screen overview on lollipop devices.
        setTitle(displayName);
        
        txtName.setText(displayName);
        txtName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast(((TextView) v).getText().toString());
            }
        });

        return true;
    }

    return false;
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:28,代码来源:ChatSDKAbstractChatActivity.java

示例4: textTouchEvent

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 微博文本触摸监听处理
 *
 * @param textView 点击的TextView
 * @param event
 * @return true:点击事件被处理;false:点击事件未被处理,向上冒泡
 */
private boolean textTouchEvent(TextView textView, MotionEvent event) {
    boolean ret = false;
    CharSequence text = textView.getText();
    Spannable sText = Spannable.Factory.getInstance().newSpannable(text);
    int action = event.getAction();
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= textView.getTotalPaddingLeft();
        y -= textView.getTotalPaddingTop();
        x += textView.getScrollX();
        y += textView.getScrollY();
        Layout layout = textView.getLayout();
        int line = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(line, x);
        ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class);
        if (links.length != 0) {
            if (action == MotionEvent.ACTION_UP) {
                links[0].onClick(textView);
            }
            ret = true;
        }
    }
    return ret;
}
 
开发者ID:liying2008,项目名称:Simpler,代码行数:33,代码来源:StatusDataSetter.java

示例5: getString

import android.widget.TextView; //导入方法依赖的package包/类
/**获取string,为null则返回""
 * @param tv
 * @return
 */
public static String getString(TextView tv) {
	if (tv == null || tv.getText() == null) {
		return "";
	}
	return getString(tv.getText().toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:StringUtil.java

示例6: onClick

import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onClick(View textView) {
    TextView tv = (TextView) textView;
    Spanned s = (Spanned) tv.getText();
    int start = s.getSpanStart(this);
    int end = s.getSpanEnd(this);
    clickListener.onClick(type, s.subSequence(start, end).toString().trim());
}
 
开发者ID:bachors,项目名称:Android-WordToSpan,代码行数:9,代码来源:WordToSpan.java

示例7: getAccessibilityText

import android.widget.TextView; //导入方法依赖的package包/类
@Override
public CharSequence getAccessibilityText() {
    if (mView == null) return "";
    TextView messageView = (TextView) mView.findViewById(R.id.infobar_message);
    if (messageView == null) return "";
    return messageView.getText() + mContext.getString(R.string.bottom_bar_screen_position);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:8,代码来源:InfoBar.java

示例8: extract

import android.widget.TextView; //导入方法依赖的package包/类
private static Object[] extract(@NonNull TextView view) {
    final Object[] out;
    final CharSequence text = view.getText();
    if (!TextUtils.isEmpty(text) && text instanceof Spanned) {
        out = ((Spanned) text).getSpans(0, text.length(), TableRowSpan.class);
    } else {
        out = null;
    }
    return out;
}
 
开发者ID:noties,项目名称:Markwon,代码行数:11,代码来源:TableRowsScheduler.java

示例9: stripUnderlines

import android.widget.TextView; //导入方法依赖的package包/类
public static void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:13,代码来源:URLSpanNoUnderline.java

示例10: convert

import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void convert(final BaseViewHolder helper, final WaitMovieBean.DataBean.ComingBean item) {
    helper.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ToastUtil.showShort(mContext, helper.getAdapterPosition() + "");
        }
    });

    // 图片地址不能直接使用,需要进行转换
    String originUrl = item.getImg();
    String imgUrl = originUrl.replace("/w.h/", "/") + "@171w_240h_1e_1c_1l";//后缀为图片大小
    GlideManager.loadImage(mContext, imgUrl, (ImageView) helper.getView(R.id.iv_wait_movie));

    helper.setText(R.id.tv_wait_movie_name, item.getNm())
            .setText(R.id.tv_wait_movie_desc, item.getScm())
            .setText(R.id.tv_wait_movie_wish, String.format("%s人想看", item.getWish()))
            .setText(R.id.tv_wait_movie_major, String.format("主演:%s", item.getStar()));

    TextView tv_wish = helper.getView(R.id.tv_wait_movie_wish);
    Spannable spannable = new SpannableString(tv_wish.getText());
    spannable.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.text_yellow, null)), 0, tv_wish.getText().toString().indexOf("人想看"), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv_wish.setText(spannable);

    helper.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MovieDetailActivity.invoke(mContext, item.getId());
        }
    });
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:32,代码来源:WaitMovieAdapter.java

示例11: layoutDebugInfo

import android.widget.TextView; //导入方法依赖的package包/类
private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView,
        final int x) {
    final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
    final CharSequence debugInfo = debugInfoView.getText();
    if (debugInfo == null) {
        return;
    }
    placerView.addView(debugInfoView);
    debugInfoView.measure(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int infoWidth = debugInfoView.getMeasuredWidth();
    final int y = debugInfoView.getMeasuredHeight();
    ViewLayoutUtils.placeViewAt(
            debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:16,代码来源:SuggestionStripLayoutHelper.java

示例12: createShareIntent

import android.widget.TextView; //导入方法依赖的package包/类
private Intent createShareIntent() {
    String msg = mRecipe.getName() + "\n" + "----\n" +
            getString(R.string.ingredients_title) + ":\n" + "----\n";
    for(TextView ingredient : mIngredientList){
        msg += ingredient.getText() + "\n";
    }
    msg += getString(R.string.steps_title) + ":\n" + "----\n";
    for(Step step : mStepList){
        msg += step.getShortDescription() + "\n";
    }
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
    return shareIntent;
}
 
开发者ID:twisstosin,项目名称:UdacityBakingAndroid,代码行数:16,代码来源:RecipeDetailFragment.java

示例13: clickClickableSpan

import android.widget.TextView; //导入方法依赖的package包/类
public static ViewAction clickClickableSpan(final CharSequence textToClick) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return instanceOf(TextView.class);
        }

        @Override
        public String getDescription() {
            return "clicking on a ClickableSpan";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView textView = (TextView) view;
            SpannableString spannableString = (SpannableString) textView.getText();

            if (spannableString.length() == 0) {
                // TextView is empty, nothing to do
                throw new NoMatchingViewException.Builder()
                        .includeViewHierarchy(true)
                        .withRootView(textView)
                        .build();
            }

            // Get the links inside the TextView and check if we find textToClick
            ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
            if (spans.length > 0) {
                ClickableSpan spanCandidate;
                for (ClickableSpan span : spans) {
                    spanCandidate = span;
                    int start = spannableString.getSpanStart(spanCandidate);
                    int end = spannableString.getSpanEnd(spanCandidate);
                    CharSequence sequence = spannableString.subSequence(start, end);
                    if (textToClick.toString().equals(sequence.toString())) {
                        span.onClick(textView);
                        return;
                    }
                }
            }

            // textToClick not found in TextView
            throw new NoMatchingViewException.Builder()
                    .includeViewHierarchy(true)
                    .withRootView(textView)
                    .build();

        }
    };
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:51,代码来源:EspressoTestUtils.java

示例14: setColorSpanOnTextView

import android.widget.TextView; //导入方法依赖的package包/类
private void setColorSpanOnTextView(TextView view, String fulltext, String subtext, int color) {
    view.setText(fulltext, TextView.BufferType.SPANNABLE);
    Spannable str = (Spannable) view.getText();
    int i = fulltext.indexOf(subtext);
    str.setSpan(new ForegroundColorSpan(color), i, i + subtext.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
开发者ID:r3bl-alliance,项目名称:stay-awake-app,代码行数:8,代码来源:MainActivity.java

示例15: getHeaderText

import android.widget.TextView; //导入方法依赖的package包/类
public CharSequence getHeaderText() {
    final TextView titleView = getHeaderTextView();
    return titleView != null ? titleView.getText() : null;
}
 
开发者ID:Trumeet,项目名称:SetupWizardLibCompat,代码行数:5,代码来源:SetupWizardLayout.java


注:本文中的android.widget.TextView.getText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。