Example usage for android.widget TextView TextView

List of usage examples for android.widget TextView TextView

Introduction

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

Prototype

public TextView(Context context) 

Source Link

Usage

From source file:cn.caimatou.canting.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. ja  va 2 s.  c o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    int textSize = (mTextSize <= 0 ? TAB_VIEW_TEXT_SIZE_SP : mTextSize);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    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);

    return textView;
}

From source file:com.app.learn.Util.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  w w.  j a v  a2s  .co  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView 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.setTextColor(Color.WHITE); // \(^o^)/ ???? TextColor

    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.google.zxing.client.android.CaptureActivity.java

private void initConView() {
    mToolView = new ViewToolView(this, mData, toolListener);
    RelativeLayout.LayoutParams toolParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);/*from   w ww.j av a  2  s  . co m*/
    int top = (int) getResources().getDimension(EUExUtil.getResDimenID("plugin_uexscanner_tool_top"));
    int left = (int) getResources().getDimension(EUExUtil.getResDimenID("plugin_uexscanner_tool_left"));
    toolParams.setMargins(left, top, left, 0);
    mToolView.setId(1);
    mToolView.setLayoutParams(toolParams);
    mConRel.addView(mToolView);

    viewfinderView = new ViewfinderView(this, mData);
    RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    viewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    viewfinderView.setLayoutParams(viewParams);
    mConRel.addView(viewfinderView);

    mGalleryPic = new ImageView(this);
    RelativeLayout.LayoutParams picParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    picParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    picParams.addRule(RelativeLayout.BELOW, 1);
    picParams.setMargins(left, top, left, top);
    mGalleryPic.setLayoutParams(picParams);
    mConRel.addView(mGalleryPic);

    mGalleryPic.setVisibility(View.GONE);

    mFailText = new TextView(this);
    RelativeLayout.LayoutParams failTextParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    failTextParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mFailText.setLayoutParams(failTextParams);
    mFailText.setGravity(Gravity.CENTER);
    mFailText.setTextColor(Color.WHITE);
    mFailText.setTextSize(25);
    mConRel.addView(mFailText);

    mFailText.setVisibility(View.GONE);
    mFailText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFailText.setVisibility(View.GONE);
            mGalleryPic.setVisibility(View.GONE);
        }
    });

}

From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationMapFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    currentlyRouting = false;//  www . ja v a  2 s. c  o m

    pathOverlay = new PathOverlay(getRouteColor(), getActivity());

    if (getActivity().getIntent().getExtras() != null) {
        startLocation = Util.locationFromCoordinates(
                getActivity().getIntent().getExtras().getDouble("start_lat"),
                getActivity().getIntent().getExtras().getDouble("start_lng"));
        endLocation = Util.locationFromCoordinates(getActivity().getIntent().getExtras().getDouble("end_lat"),
                getActivity().getIntent().getExtras().getDouble("end_lng"));
        if (getActivity().getIntent().getExtras().containsKey("json_root"))
            jsonRoot = Util.stringToJsonNode(getActivity().getIntent().getExtras().getString("json_root"));
        source = getActivity().getIntent().getExtras().getString("source");
        destination = getActivity().getIntent().getExtras().getString("destination");
    }

    getMapActivity().stopTrackingUser();
    if (getActivity().getIntent().getExtras().containsKey("start_name"))
        this.startName = getActivity().getIntent().getExtras().getString("start_name");
    if (getActivity().getIntent().getExtras().containsKey("end_name"))
        this.endName = getActivity().getIntent().getExtras().getString("end_name");
    start(startLocation, endLocation, jsonRoot, startName, endName);
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    textA = new TextView(getActivity());
    textA.setBackgroundResource(R.drawable.rounded_rectangle_22);
    textA.setTypeface(IbikeApplication.getNormalFont());
    textA.setTextColor(Color.BLACK);
    textA.setGravity(Gravity.CENTER);
    textA.setPadding(Util.dp2px(5), Util.dp2px(5), Util.dp2px(5), Util.dp2px(5));
    textA.setVisibility(View.GONE);
    textA.setTextSize(16);
    textA.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            textA.setVisibility(View.GONE);
        }
    });
    mapView.addView(textA);
    textB = new TextView(getActivity());
    textB.setBackgroundResource(R.drawable.rounded_rectangle_22);
    textB.setTypeface(IbikeApplication.getNormalFont());
    textB.setTextColor(Color.BLACK);
    textB.setGravity(Gravity.CENTER);
    textB.setPadding(Util.dp2px(5), Util.dp2px(5), Util.dp2px(5), Util.dp2px(5));
    textB.setVisibility(View.GONE);
    textB.setTextSize(16);
    textB.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            textB.setVisibility(View.GONE);
        }
    });
    mapView.addView(textB);

    locationOverlay.setMapFragment(this);

    mapView.directionShown = true;
    mapView.isNavigation = true;

}

From source file:com.brianwu.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 ww  w. java  2 s  . c o m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(context.getResources().getColor(R.color.txt_gray_white));
    textView.setTextSize(16);
    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);
    }

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

    return textView;
}

From source file:com.arce.angel.request.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)}./*from  w ww . j  a v a2s .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);

    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.alimuzaffar.ramadanalarm.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)}./*from   ww w. j  ava  2s .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);
    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);
    if (mTextColor > 0) {
        textView.setTextColor(getContext().getResources().getColor(mTextColor));
    }

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

    return textView;
}

From source file:br.comoferta.ui.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 www. jav  a 2  s.  c  o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    ColorStateList colorStateList = new ColorStateList(new int[][] {
            new int[] { android.R.attr.state_selected }, new int[] { -android.R.attr.state_selected }, },
            new int[] { Color.WHITE, Color.LTGRAY });

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextColor(colorStateList);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    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);

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

    return textView;
}

From source file:com.coreview.views.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 2s  .  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.setTextColor(Color.WHITE);

    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:cl.lezorich.pagerslidingtablayout.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 a 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);
    textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));

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