List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java
private void startNavigation(final Context context) { final NavItem[] items = { new NavItem(" " + getString(R.string.nav_oepnv), R.drawable.ic_directions_bus_gray_24px), new NavItem(" " + getString(R.string.nav_car), R.drawable.ic_directions_car_gray_24px), new NavItem(" " + getString(R.string.nav_bike), R.drawable.ic_directions_bike_gray_24px), new NavItem(" " + getString(R.string.nav_walk), R.drawable.ic_directions_walk_gray_24px), new NavItem(" " + getString(R.string.nav_show), R.drawable.ic_info_gray_24px) }; ListAdapter adapter = new ArrayAdapter<NavItem>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) { public View getView(int position, View convertView, ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); int dp7 = (int) (20 * getResources().getDisplayMetrics().density); tv.setCompoundDrawablePadding(dp5); tv.setPadding(dp7, 0, 0, 0); return v; }// www.j a va2 s . c om }; AlertDialog.Builder navBuilder = new AlertDialog.Builder(this); navBuilder.setIcon(R.mipmap.ic_launcher); navBuilder.setTitle(R.string.navMethod); navBuilder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int navItem) { String dlocation = ""; Intent intent = null; switch (navItem) { case 0: dlocation = String.format("google.navigation:ll=%s,%s&mode=Transit", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 0", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 1: dlocation = String.format("google.navigation:ll=%s,%s&mode=d", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 1", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 2: dlocation = String.format("google.navigation:ll=%s,%s&mode=b", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 2", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 3: dlocation = String.format("google.navigation:ll=%s,%s&mode=w", bahnhof.getLat(), bahnhof.getLon()); Log.d("findnavigation case 3", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; case 4: dlocation = String.format("geo:0,0?q=%s,%s(%s)", bahnhof.getLat(), bahnhof.getLon(), bahnhof.getTitle()); Log.d("findnavigation case 4", dlocation); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation)); break; } try { startActivity(intent); } catch (Exception e) { Toast toast = Toast.makeText(context, R.string.activitynotfound, Toast.LENGTH_LONG); toast.show(); } } }).show(); }
From source file:com.clairvoyant.Components.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 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); // textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, // 50, 1f)); 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 padding = TAB_VIEW_PADDING_DIPS; textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.example.abner.dynamicfragment.view.CustomSlidingTabLayout.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.ja va2 s. c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextColor(dTextColor); // mTextSize is sp textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); if (mNeedBold) { 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); if (mShouldExpand) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1; textView.setLayoutParams(layoutParams); } return textView; }
From source file:com.do_an_httt.truon_000.jobssocialnetwork.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 w w . j a v a 2 s. c o m */ protected TextView createDefaultTabView(Context context) { int width_device = getResources().getDisplayMetrics().widthPixels; TextView textView = new TextView(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width_device / 3, ViewGroup.LayoutParams.MATCH_PARENT); textView.setLayoutParams(params); 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.dashboard.orange.orangedashboard.CustomLayout.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 .jav a2 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.setTextColor(getResources().getColor(R.color.white)); textView.setLayoutParams( new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); 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.duckduckgo.mobile.android.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 ww . ja v a2 s . c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.TOP | Gravity.CENTER); textView.setTextAppearance(context, R.style.TabTitle); textView.setHeight((int) getResources().getDimension(R.dimen.actionbar_tab_height2)); 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 halfPadding = (int) (padding * 0.5); //textView.setPadding(padding, padding, padding, padding); textView.setPadding(padding, halfPadding, padding, padding); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int width; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point size = new Point(); display.getSize(size); width = size.x; } else { width = display.getWidth(); } if (width > getResources().getDimension(R.dimen.tab_small) || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { textView.setWidth(width / mViewPager.getAdapter().getCount()); } 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)}.//from ww w . 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.presisco.example.slidingtabsicons.slidingtabsicons.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, int)}. *//*from w ww .j av a 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.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 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.materialdesign.view.tab.TabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * .//from w w w . j a v a 2s. c o m */ protected View createDefaultTabView(Context context) { View tabView = LayoutInflater.from(context).inflate(R.layout.tab_layout, null); TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextDefaultSize); textView.setTypeface(Typeface.DEFAULT); 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) (mTabViewDefaultPadding * getResources().getDisplayMetrics().density); textView.setPadding(0, padding, 0, padding); return tabView; }
From source file:com.xda.one.ui.widget.TabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set * via//from w w w. ja v a 2 s. c om * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); // Modified for XDA One final TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceSmallInverse, typedValue, true); textView.setTextAppearance(getContext(), typedValue.resourceId); getContext().getTheme().resolveAttribute(android.R.attr.textColorPrimaryInverse, typedValue, true); textView.setTextColor(getResources().getColor(typedValue.resourceId)); textView.setTypeface(null, Typeface.BOLD); // Customized for app textView.setLayoutParams( new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f / mViewPager.getAdapter().getCount())); textView.setSingleLine(); AutofitHelper.create(textView); // Modified for XDA One getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true); textView.setBackgroundResource(typedValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }