Example usage for android.widget TextView setWidth

List of usage examples for android.widget TextView setWidth

Introduction

In this page you can find the example usage for android.widget TextView setWidth.

Prototype

@android.view.RemotableViewMethod
public void setWidth(int pixels) 

Source Link

Document

Sets the width of the TextView to be exactly pixels wide.

Usage

From source file:com.restswitch.controlpanel.MainActivity.java

public void setProgressBars(String pb1Text, int pb1Pos, String pb2Text, int pb2Pos) {
    ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar);
    pb.setProgress(pb1Pos);/*w ww. j  a  va 2s. c om*/
    pb.setSecondaryProgress(pb2Pos);

    TextView tv1 = (TextView) findViewById(R.id.progressBarText);
    tv1.setText(pb1Text);

    TextView tv2 = (TextView) findViewById(R.id.secondaryProgressBarText);
    tv2.setText(pb2Text);

    int pbwTot = pb.getWidth();
    int pbw1 = ((pbwTot * pb1Pos) / 100);
    tv1.setWidth(pbw1);

    pbw1 += 96;
    int pbw2 = (pbwTot - pbw1);
    ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) tv2.getLayoutParams();
    mlp.setMargins(pbw1, 2, 0, 0);
    tv2.setWidth(pbw2);
}

From source file:com.hybunion.member.view.PagerSlidingTabStrip.java

private void addTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setWidth(screenWidth / tabCount);// 
    tab.setText(title);//from  w w  w.j  a  va 2s.  c  om
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:com.softminds.matrixcalculator.base_fragments.ViewMatrixFragment.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    int index = getArguments().getInt("INDEX");

    View v = inflater.inflate(R.layout.view_matrix_frag, container, false);
    CardView cardView = v.findViewById(R.id.DynamicCardView);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
    String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");

    cardView.setCardElevation(Integer.parseInt(string));

    final int border = getResources().getDimensionPixelOffset(R.dimen.border_width);

    CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    cardView.setUseCompatPadding(true);// ww w.  j  a  v a  2s  .  co m

    GridLayout gridLayout = new GridLayout(getContext());
    int rows = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).getNumberOfRows();
    int cols = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).getNumberOfCols();

    gridLayout.setRowCount(rows);
    gridLayout.setColumnCount(cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            TextView textView = new TextView(getContext());
            textView.setGravity(Gravity.CENTER);
            textView.setBackgroundColor(Color.parseColor(string2));
            textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication())
                    .GetCompleteList().get(index).getElementOf(i, j)), getLength()));
            textView.setWidth(CalculatedWidth(cols));
            textView.setTextSize(SizeReturner(rows, cols, PreferenceManager
                    .getDefaultSharedPreferences(getContext()).getBoolean("EXTRA_SMALL_FONT", false)));
            textView.setHeight(CalculatedHeight(rows));
            GridLayout.Spec Row = GridLayout.spec(i, 1);
            GridLayout.Spec Col = GridLayout.spec(j, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
            params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = border;
            gridLayout.addView(textView, params);
        }
    }
    gridLayout.setLayoutParams(params1);
    cardView.addView(gridLayout);

    // Inflate the layout for this fragment
    return v;
}

From source file:com.yanshi.my36kr.common.view.slidingTab.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*ww  w. j  a v a 2s . com*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    /**
     * ?tab??
     */
    if (screenX != 0)
        textView.setWidth(screenX);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.example.xiner.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from   w  w w  .  j a  v  a  2 s.c o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = windowManager.getDefaultDisplay().getWidth();
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setWidth(width / 3);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:cn.scujcc.bug.bitcoinplatformandroid.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab
 * view is not set via {@link #setCustomTabView(int, int)}.
 *///from w  w  w.  j  a  va  2  s. c  o  m

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setWidth(screenX);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the
        // Theme's
        // selectableItemBackground to ensure that the View has a pressed
        // state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the
        // Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.spotters.spotterapp.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*  www  . j  a  va 2  s.co m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 5);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.example.sdave.footballscore.SlidingTabs.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   w  w w. j a v  a2 s.c  o m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.randomappsinc.bro.Layouts.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./* www  .jav  a2 s . c  o m*/
 */
protected TextView createDefaultTabView(Context context) {

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / numTabs);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java

private void onTooltipIconClicked() {
    // Don't show the popup if there's already one showing (or one has been dismissed
    // recently). This prevents a tap on the (?) from hiding and then immediately re-showing
    // the popup.
    if (mStoreLocallyTooltipPopup != null)
        return;//from  w w  w  .j  av a  2  s  . c  o m

    mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext());
    TextView text = new TextView(mDialog.getContext());
    text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip);
    // Width is the dialog's width less the margins and padding around the checkbox and
    // icon.
    text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mStoreLocallyCheckbox)
            - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon)
            - MarginLayoutParamsCompat
                    .getMarginStart((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLayoutParams())
            - MarginLayoutParamsCompat
                    .getMarginEnd((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.getLayoutParams()));
    text.setTextColor(Color.WHITE);
    Resources resources = mDialog.getContext().getResources();
    int hPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_horizontal_padding);
    int vPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_vertical_padding);
    text.setPadding(hPadding, vPadding, hPadding, vPadding);

    mStoreLocallyTooltipPopup.setContentView(text);
    mStoreLocallyTooltipPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setOutsideTouchable(true);
    mStoreLocallyTooltipPopup.setBackgroundDrawable(
            ApiCompatibilityUtils.getDrawable(resources, R.drawable.store_locally_tooltip_background));
    mStoreLocallyTooltipPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Handler h = new Handler();
            h.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mStoreLocallyTooltipPopup = null;
                }
            }, 200);
        }
    });
    mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox,
            ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0);
    text.announceForAccessibility(text.getText());
}