List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:edu.rowan.app.carousel.CarouselFeature.java
private void setupView() { imageView.setId(1);//from w w w.j av a 2s . com RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); imageView.setLayoutParams(imageParams); // imageView.setAdjustViewBounds(true); Resources r = context.getResources(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); TextView descriptionView = new TextView(context); descriptionView.setId(2); descriptionView.setPadding(padding, 0, padding, padding); descriptionView.setText(description); descriptionView.setBackgroundColor(Color.argb(220, 63, 26, 10)); descriptionView.setTextColor(Color.WHITE); RelativeLayout.LayoutParams descParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); descParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageView.getId()); carouselView.addView(descriptionView, descParams); TextView titleView = new TextView(context); titleView.setText(title); titleView.setPadding(padding, 0, padding, 0); RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); titleParams.addRule(RelativeLayout.ABOVE, descriptionView.getId()); titleView.setLayoutParams(titleParams); titleView.setTextColor(Color.WHITE); titleView.setShadowLayer(2, 3, 3, Color.argb(230, 0, 0, 0)); titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); carouselView.addView(titleView); }
From source file:com.tweetlanes.android.core.view.PlaceholderPagerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) { mContent = savedInstanceState.getString(KEY_CONTENT); }/*w w w . ja va 2s . c o m*/ TextView text = new TextView(getActivity()); text.setGravity(Gravity.CENTER); text.setText(mContent); text.setTextSize(20 * getResources().getDisplayMetrics().density); text.setPadding(20, 20, 20, 20); LinearLayout layout = new LinearLayout(getActivity()); layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); layout.setGravity(Gravity.CENTER); layout.addView(text); setInitialDownloadState(InitialDownloadState.DOWNLOADED); return layout; }
From source file:com.undatech.opaque.dialogs.SelectTextElementFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { android.util.Log.e(TAG, "onCreateView called"); XmlPullParser parser = getResources().getXml(R.layout.textelement); AttributeSet attributes = Xml.asAttributeSet(parser); // Set title for this dialog getDialog().setTitle(title);// w w w . j ava2 s .c om View v = inflater.inflate(R.layout.select_text, container, false); verticalLayout = (LinearLayout) v.findViewById(R.id.verticalLayout); ListIterator<String> iter = strings.listIterator(); while (iter.hasNext()) { android.util.Log.e(TAG, "Adding element to dialog"); String string = iter.next(); TextView element = new TextView(v.getContext(), attributes); element.setText(string); element.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 25.f); element.setPadding(40, 20, 40, 20); element.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SelectTextElementFragment.this.selected = ((TextView) v).getText().toString(); SelectTextElementFragment.this.dismiss(); } }); verticalLayout.addView(element); } return v; }
From source file:com.fizz.StickyFragment.java
@Override public void onStart() { super.onStart(); LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.ll); for (int i = 0; i < drinks.length; i++) { TextView tt = new TextView(getActivity()); tt.setText(drinks[i].toUpperCase(Locale.US) + "\n" + ingredients[i]); tt.setPadding(15, 15, 15, 15); tt.setOnClickListener(new OnClickListener() { @Override/* w ww . ja va2 s . c om*/ public void onClick(View v) { drink = ((TextView) v).getText().toString(); try { Intent venmoIntent = VenmoLibrary.openVenmoPayment("1684", "Fizz", "8123744601", "0.01", drink, "pay"); startActivityForResult(venmoIntent, 1); // 1 is the requestCode we are using for Venmo. Feel // free to change this to another number. // Venmo native app not install on device, so let's // instead open a mobile web version of Venmo in a // WebView } catch (android.content.ActivityNotFoundException e) { Log.e("Fizz", "onClicked"); { Intent venmoIntent = new Intent(getActivity(), VenmoWebViewActivity.class); String venmo_uri = VenmoLibrary.openVenmoPaymentInWebView("1684", "Fizz", "8123744601", "0.01", "Drink", "pay"); venmoIntent.putExtra("url", venmo_uri); startActivityForResult(venmoIntent, 1); } //} catch (android.content.ActivityNotFoundException e) { //e.printStackTrace() ; } } }); tt.setTextSize(22); if (textnum % 2 == 0) { tt.setBackgroundColor(Color.argb(0, 51, 181, 229)); tt.setTextColor(Color.argb(255, 51, 181, 229)); } else { tt.setBackgroundColor(Color.argb(240, 51, 181, 229)); tt.setTextColor(Color.argb(255, 255, 255, 255)); } tt.setTypeface(SplashActivity.tp); ll.addView(tt); textnum++; } }
From source file:com.karthikb351.vitinfo2.fragment.grades.GradesFragment.java
TextView createTextView(String text) { TextView tv = new TextView(getActivity()); tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tv.setGravity(Gravity.CENTER);//from w w w . j av a 2 s.c o m tv.setTextSize(18); tv.setPadding(0, 5, 0, 5); tv.setText(text); return tv; }
From source file:de.j4velin.pedometer.ui.Activity_Main.java
public boolean optionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case android.R.id.home: getFragmentManager().popBackStackImmediate(); break;/*from ww w. j a v a 2 s . c o m*/ case R.id.action_settings: getFragmentManager().beginTransaction().replace(android.R.id.content, new Fragment_Settings()) .addToBackStack(null).commit(); break; case R.id.action_leaderboard: case R.id.action_achievements: if (mGoogleApiClient.isConnected()) { startActivityForResult(item.getItemId() == R.id.action_achievements ? Games.Achievements.getAchievementsIntent(mGoogleApiClient) : Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient), RC_LEADERBOARDS); } else { AlertDialog.Builder builder2 = new AlertDialog.Builder(this); builder2.setTitle(R.string.sign_in_necessary); builder2.setMessage(R.string.please_sign_in_with_your_google_account); builder2.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); getFragmentManager().beginTransaction() .replace(android.R.id.content, new Fragment_Settings()).addToBackStack(null) .commit(); } }); builder2.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder2.create().show(); } break; case R.id.action_faq: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://j4velin.de/faq/index.php?app=pm")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); break; case R.id.action_about: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.about); TextView tv = new TextView(this); tv.setPadding(10, 10, 10, 10); tv.setText(R.string.about_text_links); try { tv.append(getString(R.string.about_app_version, getPackageManager().getPackageInfo(getPackageName(), 0).versionName)); } catch (NameNotFoundException e1) { // should not happen as the app is definitely installed when // seeing the dialog e1.printStackTrace(); } tv.setMovementMethod(LinkMovementMethod.getInstance()); builder.setView(tv); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); break; } return true; }
From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java
public TextView createTextView(String text, int size, LayoutInflater inflater, ViewGroup group) { // TextView t = (TextView) inflater.inflate(R.layout.plan_text, group, true).findViewById(R.id.plan_entry); TextView t = new TextView(getActivity()); t.setText(text);/*from w w w . j a v a 2s . c o m*/ t.setPadding(0, 0, toPixels(20), 0); t.setTextSize(size); group.addView(t); return t; }
From source file:co.ldln.android.ObjectReadFragment.java
@Override public void onReadSchemaResult(Schema schema) { mSchema = schema;//w ww . j a v a2s .c o m HashMap<String, String> keyValueMap = mSyncableObject.getKeyValueMap(); for (SchemaField schemaField : mSchema.getFields(mActivity)) { String label = schemaField.getLabel(); String value = keyValueMap.get(label); String type = schemaField.getType(); // Create a linear layout to hold the field LinearLayout ll = new LinearLayout(mActivity); LayoutParams llParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); ll.setLayoutParams(llParams); ll.setOrientation(LinearLayout.HORIZONTAL); // TODO: different UI for different field types // Default to TextView TextView labelTv = new TextView(mActivity); LayoutParams labelTvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); labelTv.setLayoutParams(labelTvParams); labelTv.setText(label); labelTv.setPadding(0, 0, 20, 0); labelTv.setTypeface(Typeface.DEFAULT_BOLD); ll.addView(labelTv); TextView valueTv = new TextView(mActivity); LayoutParams valueTvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); valueTv.setLayoutParams(valueTvParams); valueTv.setText(value); ll.addView(valueTv); mFormHolder.addView(ll); } }
From source file:com.honu.giftwise.InfoActivity.java
protected void showLicenseInfo() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("License information"); TextView tv = new TextView(this); tv.setText(Html.fromHtml(getString(R.string.isc_license))); tv.setMovementMethod(new ScrollingMovementMethod()); tv.setPadding(12, 0, 12, 0); alert.setView(tv);//from w w w . j a v a 2s.c om alert.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert.show(); }
From source file:br.org.funcate.dynamicforms.views.GTimeView.java
/** * @param fragment the fragment.//from www. j a va 2 s . c om * @param attrs attributes. * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); //newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }