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

The following examples show how to use android.widget.TextView#setPaddingRelative() . 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: RxAlertDialog.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public Builder setTitleSmall(@StringRes int titleId) {
  TextView textView = new TextView(builder.getContext());
  textView.setTextSize(12f);
  textView.setTextColor(textView.getResources()
      .getColor(R.color.secondary_text_color));
  textView.setText(titleId);

  int paddingTop = (int) (20 * textView.getResources()
      .getDisplayMetrics().density + 0.5f);
  int paddingLeft = (int) (25 * textView.getResources()
      .getDisplayMetrics().density + 0.5f);
  int paddingBottom = (int) (10 * textView.getResources()
      .getDisplayMetrics().density + 0.5f);
  textView.setPaddingRelative(paddingLeft, paddingTop, 0, paddingBottom);
  builder.setCustomTitle(textView);
  return this;
}
 
Example 2
Source File: PaymentRequestHeader.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the title and origin on the header.
 *
 * @param title         The title to display on the header.
 * @param origin        The origin to display on the header.
 * @param securityLevel The security level of the page that invoked PaymentRequest.
 */
public void setTitleAndOrigin(String title, String origin, int securityLevel) {
    ((TextView) findViewById(R.id.page_title)).setText(title);

    TextView hostName = (TextView) findViewById(R.id.hostname);
    Spannable url = new SpannableStringBuilder(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(url, mContext.getResources(),
            Profile.getLastUsedProfile(), securityLevel, false /* isInternalPage */,
            true /* useDarkColors */, true /* emphasizeHttpsScheme */);
    hostName.setText(url);

    if (origin.startsWith(UrlConstants.HTTPS_URL_PREFIX)) {
        // Add a lock icon.
        ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(hostName,
                TintedDrawable.constructTintedDrawable(mContext.getResources(),
                        R.drawable.omnibox_https_valid, R.color.google_green_700),
                null, null, null);

        // Remove left padding to align left compound drawable with the title. Note that the
        // left compound drawable has transparent boundary.
        hostName.setPaddingRelative(0, 0, 0, 0);
    }
}
 
Example 3
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void updateMenuItemButton(View menuItemButton, MenuItem menuItem, int iconTextSpacing) {
    ViewGroup viewGroup = (ViewGroup) menuItemButton;
    final TextView buttonText = (TextView) viewGroup.getChildAt(0);
    buttonText.setEllipsize(null);
    if (TextUtils.isEmpty(menuItem.getTitle())) {
        buttonText.setVisibility(View.GONE);
    } else {
        buttonText.setVisibility(View.VISIBLE);
        buttonText.setText(menuItem.getTitle());
    }
    buttonText.setPaddingRelative(0, 0, 0, 0);
    /*final CharSequence contentDescription = menuItem.getContentDescription(); TODO
    if (TextUtils.isEmpty(contentDescription)) {
        menuItemButton.setContentDescription(menuItem.getTitle());
    } else {
        menuItemButton.setContentDescription(contentDescription);
    }*/
}
 
Example 4
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void updateMenuItemButton(View menuItemButton, MenuItem menuItem, int iconTextSpacing) {
    ViewGroup viewGroup = (ViewGroup) menuItemButton;
    final TextView buttonText = (TextView) viewGroup.getChildAt(0);
    buttonText.setEllipsize(null);
    if (TextUtils.isEmpty(menuItem.getTitle())) {
        buttonText.setVisibility(View.GONE);
    } else {
        buttonText.setVisibility(View.VISIBLE);
        buttonText.setText(menuItem.getTitle());
    }
    buttonText.setPaddingRelative(0, 0, 0, 0);
    /*final CharSequence contentDescription = menuItem.getContentDescription(); TODO
    if (TextUtils.isEmpty(contentDescription)) {
        menuItemButton.setContentDescription(menuItem.getTitle());
    } else {
        menuItemButton.setContentDescription(contentDescription);
    }*/
}
 
Example 5
Source File: PhoneStatusBarViewHook.java    From XMiTools with GNU General Public License v3.0 5 votes vote down vote up
private void prepareLayoutStatusBar(XC_MethodHook.MethodHookParam param) {
    // FrameLayout
    ViewGroup phoneStatusBarView = (ViewGroup) param.thisObject;

    Context context = phoneStatusBarView.getContext();
    Resources res = context.getResources();

    //        LinearLayout statusBarContents = phoneStatusBarView.findViewById(
    //                res.getIdentifier("status_bar_contents", "id", PACKAGE_NAME));

    TextView clock = phoneStatusBarView.findViewById(
            res.getIdentifier("clock", "id", PACKAGE_NAME));
    ((ViewGroup) clock.getParent()).removeView(clock);

    if (mAlignmentCenter) {
        // 注入新的居中的layout 到 phoneStatusBarView 中去
        mCenterLayout = new LinearLayout(context);
        LinearLayout.LayoutParams lp =
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        mCenterLayout.setLayoutParams(lp);
        mCenterLayout.setGravity(Gravity.CENTER);
        phoneStatusBarView.addView(mCenterLayout);

        clock.setPaddingRelative(2, 0, 2, 0);
        clock.setGravity(Gravity.CENTER);
        mCenterLayout.addView(clock);
    } else if (mAlignmentRight) { // 居右对齐
        LinearLayout rightAreaLayout = phoneStatusBarView.findViewById(
                res.getIdentifier("system_icons", "id", PACKAGE_NAME));
        clock.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        rightAreaLayout.addView(clock);
    }
}
 
Example 6
Source File: AlertDialogsHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
private static void loadDetails(View dialogLayout, ThemedActivity activity, MediaDetailsMap<String, String> metadata) {
    LinearLayout detailsTable = dialogLayout.findViewById(R.id.ll_list_details);

    int tenPxInDp = Measure.pxToDp(10, activity);

    for (int index : metadata.getKeySet()) {
        LinearLayout row = new LinearLayout(activity.getApplicationContext());
        row.setOrientation(LinearLayout.VERTICAL);

        TextView label = new TextView(activity.getApplicationContext());
        TextView value = new TextView(activity.getApplicationContext());
        label.setText(metadata.getLabel(index));
        label.setLayoutParams((new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)));
        value.setText(metadata.getValue(index));
        value.setLayoutParams((new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)));
        label.setTextColor(activity.getTextColor());
        label.setTypeface(null, Typeface.BOLD);
        label.setGravity(Gravity.START);
        label.setTextSize(16);
        label.setPaddingRelative(tenPxInDp, tenPxInDp, tenPxInDp, tenPxInDp);
        value.setTextColor(activity.getTextColor());
        value.setTextSize(16);
        value.setPaddingRelative(tenPxInDp, tenPxInDp, tenPxInDp, tenPxInDp);
        row.addView(label);
        row.addView(value);
        detailsTable.addView(row, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    }
}
 
Example 7
Source File: MenuPopup.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
ViewHolder() {
    super(new TextView(getContext()));
    mTextView = (TextView) getItemView();
    mTextView.setTextColor(getColor(R.color.black50));
    mTextView.setTextSize(16);
    mTextView.setPaddingRelative((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
}
 
Example 8
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private View createMenuItemButton(Context context, MenuItem menuItem, int iconTextSpacing) {
    LinearLayout menuItemButton = new LinearLayout(context);
    menuItemButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    menuItemButton.setOrientation(LinearLayout.HORIZONTAL);
    menuItemButton.setMinimumWidth(AndroidUtilities.dp(48));
    menuItemButton.setMinimumHeight(AndroidUtilities.dp(48));
    menuItemButton.setPaddingRelative(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setFocusable(false);
    textView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    textView.setFocusableInTouchMode(false);
    if (currentStyle == STYLE_DIALOG) {
        textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    } else if (currentStyle == STYLE_BLACK) {
        textView.setTextColor(0xfffafafa);
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(0x40ffffff, false));
    } else if (currentStyle == STYLE_THEME) {
        textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    }
    textView.setPaddingRelative(AndroidUtilities.dp(11), 0, 0, 0);
    menuItemButton.addView(textView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtilities.dp(48)));
    if (menuItem != null) {
        updateMenuItemButton(menuItemButton, menuItem, iconTextSpacing);
    }
    return menuItemButton;
}
 
Example 9
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private View createMenuItemButton(Context context, MenuItem menuItem, int iconTextSpacing) {
    LinearLayout menuItemButton = new LinearLayout(context);
    menuItemButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    menuItemButton.setOrientation(LinearLayout.HORIZONTAL);
    menuItemButton.setMinimumWidth(AndroidUtilities.dp(48));
    menuItemButton.setMinimumHeight(AndroidUtilities.dp(48));
    menuItemButton.setPaddingRelative(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setFocusable(false);
    textView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    textView.setFocusableInTouchMode(false);
    if (currentStyle == STYLE_DIALOG) {
        textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    } else if (currentStyle == STYLE_BLACK) {
        textView.setTextColor(0xfffafafa);
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(0x40ffffff, false));
    } else if (currentStyle == STYLE_THEME) {
        textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    }
    textView.setPaddingRelative(AndroidUtilities.dp(11), 0, 0, 0);
    menuItemButton.addView(textView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtilities.dp(48)));
    if (menuItem != null) {
        updateMenuItemButton(menuItemButton, menuItem, iconTextSpacing);
    }
    return menuItemButton;
}
 
Example 10
Source File: ToastUtils.java    From ToastUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 生成默认的 TextView 对象
 */
private static TextView createTextView(Context context, IToastStyle style) {

    GradientDrawable drawable = new GradientDrawable();
    // 设置背景色
    drawable.setColor(style.getBackgroundColor());
    // 设置圆角大小
    drawable.setCornerRadius(style.getCornerRadius());

    TextView textView = new TextView(context);
    textView.setId(android.R.id.message);
    textView.setTextColor(style.getTextColor());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getTextSize());

    // 适配布局反方向
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setPaddingRelative(style.getPaddingStart(), style.getPaddingTop(), style.getPaddingEnd(), style.getPaddingBottom());
    } else {
        textView.setPadding(style.getPaddingStart(), style.getPaddingTop(), style.getPaddingEnd(), style.getPaddingBottom());
    }

    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    // setBackground API 版本兼容
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackground(drawable);
    } else {
        textView.setBackgroundDrawable(drawable);
    }

    // 设置 Z 轴阴影
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textView.setZ(style.getZ());
    }

    // 设置最大显示行数
    if (style.getMaxLines() > 0) {
        textView.setMaxLines(style.getMaxLines());
    }

    return textView;
}