Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

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

Prototype

@Override
public void setPadding(int left, int top, int right, int bottom) 

Source Link

Usage

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

private ArrayAdapter<String> popupMenuAdapter(String itemTagArray[]) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            itemTagArray) {//from   www .  j av a2  s.c o  m
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // setting the ID and text for every items in the list
            String item = getItem(position);
            String[] itemArr = item.split("::");
            String text = itemArr[0];
            String id = itemArr[1];

            // visual settings for the list item
            TextView listItem = new TextView(AnalyzeActivity.this);

            if (id.equals("0")) {
                listItem.setText(text);
                listItem.setTag(id);
                listItem.setTextSize(listItemTitleTextSize / DPRatio);
                listItem.setPadding(5, 5, 5, 5);
                listItem.setTextColor(Color.GREEN);
                listItem.setGravity(android.view.Gravity.CENTER);
            } else {
                listItem.setText(text);
                listItem.setTag(id);
                listItem.setTextSize(listItemTextSize / DPRatio);
                listItem.setPadding(5, 5, 5, 5);
                listItem.setTextColor(Color.WHITE);
                listItem.setGravity(android.view.Gravity.CENTER);
            }

            return listItem;
        }
    };
    return adapter;
}

From source file:com.ichi2.anki.CardEditor.java

private void populateEditFields() {
    mFieldsLayoutContainer.removeAllViews();
    mEditFields = new LinkedList<FieldEditText>();
    String[][] fields = mEditorNote.items();

    // Use custom font if selected from preferences
    Typeface mCustomTypeface = null;/*from   w  ww.j  av a  2 s.  c  om*/
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    String customFont = preferences.getString("browserEditorFont", "");
    if (!customFont.equals("")) {
        mCustomTypeface = AnkiFont.getTypeface(this, customFont);
    }

    for (int i = 0; i < fields.length; i++) {
        FieldEditText newTextbox = new FieldEditText(this, i, fields[i]);

        if (mCustomTypeface != null) {
            newTextbox.setTypeface(mCustomTypeface);
        }

        TextView label = newTextbox.getLabel();
        label.setTextColor(Color.BLACK);
        label.setPadding((int) UIUtils.getDensityAdjustedValue(this, 3.4f), 0, 0, 0);
        ImageView circle = newTextbox.getCircle();
        mEditFields.add(newTextbox);
        FrameLayout frame = new FrameLayout(this);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        params.rightMargin = 10;
        circle.setLayoutParams(params);
        frame.addView(newTextbox);
        frame.addView(circle);
        mFieldsLayoutContainer.addView(label);
        mFieldsLayoutContainer.addView(frame);
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

/**
 * Called when the activity is first created.
 *///  w w w .j a v a 2s.  co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BugSenseHandler.initAndStartSession(getActivity(), "44a76a8c");

    settings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    firstLoadHandler = new Handler() {
        public void handleMessage(Message msg) {
            //dialog.dismiss();
            try {
                if (EventObject.has("result")
                        && EventObject.getJSONObject("result").getBoolean("success") == true) {
                    EventDetails = EventObject.getJSONObject("result").getJSONArray("event").getJSONObject(0);

                    try {
                        //Log.e("Ack",EventDetails.getString("eventState"));
                        if (EventDetails.getString("eventState").equals("Acknowledged")
                                || EventDetails.getString("eventState").equals("1")) {
                            ackIcon.setImageResource(R.drawable.ic_acknowledged);
                            isAcknowledged = true;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "loadhandler ack image",
                                e);
                    }

                    //Log.e("EventDetails", EventDetails.toString(3));

                    try {
                        Title.setText(EventDetails.getString("device_title"));
                    } catch (Exception e) {
                        Title.setText("Unknown Device - Event Details");
                    }

                    try {
                        Component.setText(EventDetails.getString("component"));
                    } catch (Exception e) {
                        Component.setText("Unknown Component");
                    }

                    try {
                        if (!EventDetails.getString("eventClassKey").equals("")) {
                            EventClass.setText(EventDetails.getString("eventClassKey"));
                        } else {
                            EventClass.setText("Unknown Event Class");
                        }
                    } catch (Exception e) {
                        EventClass.setText("Unknown Event Class");
                    }

                    try {
                        //ImageView img = (ImageView) findViewById(R.id.summaryImage);

                        URLImageParser p = new URLImageParser(img, getActivity(), Summary);

                        String summaryText = EventDetails.getString("message");
                        Spanned htmlSpan = Html.fromHtml(summaryText, p, null);

                        //Log.e("summary",summaryText);
                        summaryText = summaryText.replaceAll("<img\\s*src=('|\")([^'>]+)'\\s*/>", "");
                        //Log.e("summary2",summaryText);

                        Summary.setText(Html.fromHtml(summaryText, null, null));

                        //Log.i("Summary", EventDetails.getString("message"));

                        try {
                            Summary.setMovementMethod(LinkMovementMethod.getInstance());
                        } catch (Exception e) {
                            e.printStackTrace();
                            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                                    "set Summary MovementMethod", e);
                            //Worth a shot
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Summary.setText("No Summary available");
                    }

                    try {
                        FirstTime.setText(EventDetails.getString("firstTime"));
                    } catch (Exception e) {
                        FirstTime.setText("No Start Date Provided");
                    }

                    try {
                        LastTime.setText(EventDetails.getString("stateChange"));
                    } catch (Exception e) {
                        LastTime.setText("No Recent Date Provided");
                    }

                    try {
                        EventCount.setText("Count: " + EventDetails.getString("count"));
                    } catch (Exception e) {
                        EventCount.setText("Count: ??");
                    }

                    try {
                        agent.setText(EventDetails.getString("agent"));
                    } catch (Exception e) {
                        agent.setText("unknown");
                    }

                    try {
                        JSONArray Log = EventDetails.getJSONArray("log");

                        int LogEntryCount = Log.length();

                        if (LogEntryCount == 0) {
                            TextView newLog = new TextView(getActivity());
                            newLog.setText("No log entries could be found");
                            LogEntries = new String[1];
                            LogEntries[0] = "No log entries could be found";
                            logList.addView(newLog);
                        } else {
                            LogEntries = new String[LogEntryCount];

                            for (int i = 0; i < LogEntryCount; i++) {
                                LogEntries[i] = "<strong>" + Log.getJSONArray(i).getString(0)
                                        + "</strong> wrote " + Log.getJSONArray(i).getString(2)
                                        + "\n<br/><strong>At:</strong> " + Log.getJSONArray(i).getString(1);

                                TextView newLog = new TextView(getActivity());
                                newLog.setText(Html.fromHtml(LogEntries[i]));
                                newLog.setPadding(0, 6, 0, 6);

                                logList.addView(newLog);
                            }
                        }
                    } catch (Exception e) {
                        TextView newLog = new TextView(getActivity());
                        newLog.setText("No log entries could be found");
                        newLog.setPadding(0, 6, 0, 6);
                        logList.addView(newLog);
                    }

                    progressbar.setVisibility(View.INVISIBLE);
                } else {
                    //Log.e("EventObject",EventObject.toString(3));
                    String errMsg = ".";
                    if (EventObject.has("type") && EventObject.getString("type").equals("exception")
                            && EventObject.has("message"))
                        errMsg = ":\n" + EventObject.getString("message");

                    Toast.makeText(getActivity(),
                            "There was an error refreshing the Event details from Zenoss" + errMsg,
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                try {
                    Toast.makeText(getActivity(),
                            "An error was encountered parsing the JSON. An error report has been sent.",
                            Toast.LENGTH_LONG).show();
                } catch (Exception e2) {
                    e.printStackTrace();
                    e2.printStackTrace();
                }

                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                        "uncaught exception within firstload", e);
            }
        }
    };
}

From source file:com.runtai.pullupsuspension.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)}./*  w ww  . j a v  a2 s.c o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    //        textView.setGravity(Gravity.CENTER);
    textView.setGravity(17);
    //        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextSize(2, 12.0F);
    textView.setTypeface(Typeface.DEFAULT);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //        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);
    if (Build.VERSION.SDK_INT >= 11) {
        TypedValue localTypedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, localTypedValue,
                true);
        textView.setBackgroundResource(localTypedValue.resourceId);
    }
    if (Build.VERSION.SDK_INT >= 14) {
        textView.setAllCaps(true);
        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding + 30, padding, padding + 30, padding);
    }
    return textView;
}

From source file:com.open.imooc.widght.tab.SmartTabLayout.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)}.// w w w.jav  a 2  s . c  o  m
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    //        textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } else 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(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.jinzht.pro.smarttablayout.SmartTabLayout.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  ww.  j av  a  2  s . c  om*/
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setSingleLine(true);
    UiHelp.textBold(textView);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } else 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(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.lixiang.weather.support.view.smarttab.SmartTabLayout.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*/
@SuppressLint("NewApi")
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    // textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        // textView.setBackgroundResource(tabViewBackgroundResId);
    } else 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(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.consumer.widget.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 av  a 2s  .co  m
 */
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {

    Resources res = context.getResources();

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

    //textView.setTypeface(Typeface.DEFAULT_BOLD);
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT, 1.0f);
    textView.setLayoutParams(param);

    int unSelColorBg = R.color.TabPager;

    textView.setTextColor(context.getResources().getColor(unSelColorBg));

    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);
    textView.setPadding(5, 17, 5, 22);

    return textView;
}

From source file:com.zeferino.bruno.pap.view.MovieDetailsSlidingTabLayout.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 av a 2s. c  om
 */
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);

    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);
    }

    boolean phone = getResources().getBoolean(R.bool.portrait_only);
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getRealSize(size);
    int width = size.x;
    int height = size.y;
    // special case for 7' inch tablets
    // if we leave padding to 16 the text title on the viewPager will be cut
    if (!phone && ((width == 1024 && height == 600) || (height == 1024 && width == 600)))
        TAB_VIEW_PADDING_DIPS = 14;

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

    return textView;
}

From source file:com.it520.activity.main.wight.SmartTabLayout.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)}./*  w  ww . j a  va2s .  com*/
 */
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } else 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(tabViewTextAllCaps);
    }

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}