Java Code Examples for android.widget.TextView.getPaint()

The following are Jave code examples for showing how to use getPaint() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: NeuTV   File: TabStrip.java   View Source Code Vote up 6 votes
/**
 * 添加指示器
 *
 * @param position
 * @param title
 */
private void addTab(final int position, CharSequence title) {
    TextView tvTab = new TextView(context);
    tvTab.setText(title);
    tvTab.setTextColor(textColor);
    tvTab.setTextSize(textSize);
    tvTab.setGravity(Gravity.CENTER);
    if(isIndicatorTextBold){
        TextPaint tp = tvTab.getPaint();
        tp.setFakeBoldText(true);
    }
    tvTab.setSingleLine();
    tvTab.setFocusable(true);
    tvTab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(position);
        }
    });
    tvTab.setPadding(indicatorMargin, 0, indicatorMargin, 0);
    container.addView(tvTab, position, expandedTabLayoutParams);
}
 
Example 2
Project: HeroVideo-master   File: VideoDetailsActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {

        String title = titles.get(position);
        TextView titleView = mSlidingTabLayout.getTitleView(position);
        TextPaint paint = titleView.getPaint();
        float textWidth = paint.measureText(title);
        mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
    }
 
Example 3
Project: BilibiliClient   File: RegionTypeDetailsActivity.java   View Source Code Vote up 5 votes
public void measureTabLayoutTextWidth(int position) {

    String titleName = titles.get(position);
    TextView titleView = mSlidingTab.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float v = paint.measureText(titleName);
    mSlidingTab.setIndicatorWidth(v / 3);
  }
 
Example 4
Project: BilibiliClient   File: TotalStationSearchActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {

    String title = titles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
  }
 
Example 5
Project: BilibiliClient   File: UserInfoDetailsActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {

    String title = titles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
  }
 
Example 6
Project: BilibiliClient   File: VideoDetailsActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {

    String title = titles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
  }
 
Example 7
Project: BilibiliClient   File: RegionTypeDetailsActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {
    String title = mTitles.get(position);
    TextView titleView = mSlidingTab.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float width = paint.measureText(title);
    mSlidingTab.setIndicatorWidth(width / 3);
}
 
Example 8
Project: BilibiliClient   File: VideoDetailsActivity.java   View Source Code Vote up 5 votes
private void measureTabLayoutTextWidth(int position) {
    String title = mTitles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
 
Example 9
Project: Hotspot-master-devp   File: StringUtils.java   View Source Code Vote up 5 votes
public static int getStringWidth(TextView tv, String text) {
    Rect bounds = new Rect();
    TextPaint paint;

    paint = tv.getPaint();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int width = bounds.width();

    return width;
}
 
Example 10
Project: chromium-for-android-56-debug-video   File: InfoBarControlLayout.java   View Source Code Vote up 5 votes
/**
 * Computes and records the minimum width required to display any of the values without
 * causing another layout pass when switching values.
 */
int computeMinWidthRequiredForValues() {
    DualControlLayout layout = getView(0, null, null);
    TextView container = (TextView) layout.getChildAt(1);

    Paint textPaint = container.getPaint();
    float longestLanguageWidth = 0;
    for (int i = 0; i < getCount(); i++) {
        float width = textPaint.measureText(getItem(i).toString());
        longestLanguageWidth = Math.max(longestLanguageWidth, width);
    }

    mMinWidthRequiredForValues = (int) Math.ceil(longestLanguageWidth);
    return mMinWidthRequiredForValues;
}
 
Example 11
Project: QRScanner   File: SystemUtils.java   View Source Code Vote up 5 votes
/**
 * 判断TextView的内容宽度是否超出其可用宽度
 *
 * @param tv
 * @return
 */
public static boolean isOverFlowed(TextView tv, int maxWidth) {
    int availableWidth = maxWidth - tv.getPaddingLeft() - tv.getPaddingRight();
    Paint textViewPaint = tv.getPaint();
    float textWidth = textViewPaint.measureText(tv.getText().toString());
    if (textWidth > availableWidth) {
        return true;
    } else {
        return false;
    }
}
 
Example 12
Project: AdaptationX-android   File: TextViewManager.java   View Source Code Vote up 5 votes
/**
 *返回 TextView 里面 String 所占的行数
 * @param textView
 * @param tvWidth textView 在屏幕上显示的宽(也就是 textView 父容器赐予的最大宽)
 * @return 行数
 */
public static int getRow(TextView textView,int tvWidth){
    TextPaint paint = textView.getPaint();
    float len = paint.measureText(textView.getText().toString());
    // 行数 = textWidth/控件显示在屏幕上的宽(父容器允许的最大宽度) ;
    int width = tvWidth - textView.getPaddingLeft() - textView.getPaddingRight();// 需要去掉每一行的 padding 值
    return (int)Math.ceil(len/width);
}
 
Example 13
Project: PicShow-zhaipin   File: ClassifyAdapter.java   View Source Code Vote up 5 votes
private int getTextWidth(TextView textView) {
    if (textView == null) {
        return 0;
    }
    Rect bounds = new Rect();
    String text = textView.getText().toString();
    Paint paint = textView.getPaint();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int width = bounds.left + bounds.width();
    return width;
}
 
Example 14
Project: android-dialer   File: ViewUtil.java   View Source Code Vote up 5 votes
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
  final Paint paint = textView.getPaint();
  final int width = textView.getWidth();
  if (width == 0) {
    return;
  }
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
  float ratio = width / paint.measureText(textView.getText().toString());
  if (ratio <= 1.0f) {
    textView.setTextSize(
        TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
  }
}
 
Example 15
Project: HtmlNative   File: StyleHelper.java   View Source Code Vote up 4 votes
public static void setBold(TextView textView) {
    if (textView != null) {
        TextPaint paint = textView.getPaint();
        paint.setFakeBoldText(true);
    }
}
 
Example 16
Project: amap   File: MIP_TextStyle.java   View Source Code Vote up 4 votes
public static void setFakeBold(TextView textView, boolean isBold)
{
    TextPaint tp = textView.getPaint();
    tp.setFakeBoldText(isBold);
}
 
Example 17
Project: GoMeet   File: MapsMarkerActivity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Retrieve the content view that renders the map.
        setContentView(R.layout.activity_maps);
        // Add title
        getSupportActionBar().setTitle("Event Details");
        // Add Back button
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        // Get intent
        Intent intename = getIntent();
//        nameString = (String) intename.getSerializableExtra("NAME");
//        timeString = (String) intename.getSerializableExtra("TIME");
        nameString = "lalala";
        timeString = "24:00";
        descriptionString = (String) intename.getSerializableExtra("PostText");
        lat = (double) intename.getSerializableExtra("LAT");
        lng = (double) intename.getSerializableExtra("LNG");
//        zipcodeString = (String) intename.getSerializableExtra("ZIPCODE");
//        addressString = (String) intename.getSerializableExtra("ADDRESS");
        zipcodeString = "02215";
        addressString = "PHO";
        location = new LatLng(lat, lng);
        // Get the SupportMapFragment and request notification
        // when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        // Get TextView
        name = (TextView) findViewById(R.id.Name);
        time = (TextView) findViewById(R.id.Time);
        description = (TextView) findViewById(R.id.Description);
        // Get Button
        mapAppCtrl = (Button) findViewById(R.id.openMap);
        mapAppCtrl.setOnClickListener(new MapsMarkerActivity.ButtonClickHandler());
        // Set TextView uneditable
        name.setKeyListener(null);
        time.setKeyListener(null);
        description.setKeyListener(null);
        // Set TextView size and bold
        name.setTextSize(20);
        time.setTextSize(10);
        TextPaint paint = name.getPaint();
        paint.setFakeBoldText(true);
        //Set content
        name.setText(nameString);
        time.setText(timeString);
        description.setText(String.format("%s\n%s\n%s", descriptionString, addressString, zipcodeString));
    }
 
Example 18
Project: stynico   File: TextDrawable.java   View Source Code Vote up 3 votes
/**
 * Create a TextDrawable. This uses the given TextView to initialize paint and has initial text
 * that will be drawn. Initial text can also be useful for reserving space that may otherwise
 * not be available when setting compound drawables.
 *
 * @param tv               The TextView / EditText using to initialize this drawable
 * @param initialText      Optional initial text to display
 * @param bindToViewsText  Should this drawable mirror the text in the TextView
 * @param bindToViewsPaint Should this drawable mirror changes to Paint in the TextView, like textColor, typeface, alpha etc.
 *                         Note, this will override any changes made using setColorFilter or setAlpha.
 */
public TextDrawable(TextView tv, String initialText, boolean bindToViewsText, boolean bindToViewsPaint) {
    this(tv.getPaint(), initialText);
    ref = new WeakReference<>(tv);
    if (bindToViewsText || bindToViewsPaint) {
        if (bindToViewsText) {
            tv.addTextChangedListener(this);
        }
        mBindToViewPaint = bindToViewsPaint;
    }
}
 
Example 19
Project: FriendBook   File: PagerSlidingTabStrip.java   View Source Code Vote up 2 votes
/**
 * z.chu
 * @param tv
 * @return  textview contentwidth
 */
public float getTextViewContentWidth(TextView tv) {
	TextPaint textPaint = tv.getPaint();
	return textPaint.measureText(tv.getText() + "");
}
 
Example 20
Project: Ftc2018RelicRecovery   File: HalDashboard.java   View Source Code Vote up 2 votes
/**
 * This method sets the TextView object from which to query the typeface measurement for centering/right justifying
 * messages. You don't need to call this method if you never centered or right justified messages on the dashboard.
 *
 * @param textView specifies the TextView object.
 */
public void setTextView(TextView textView)
{
    this.paint = textView.getPaint();
}