List of usage examples for android.widget TextView setLineSpacing
public void setLineSpacing(float add, float mult)
From source file:com.koushikdutta.superuser.ActivityIntro.java
@Override public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { super.onSlideChanged(oldFragment, newFragment); if (newFragment != null && newFragment.getView() != null) { View parent = newFragment.getView(); TextView title = (TextView) parent.findViewById(R.id.title); if (title != null) { if (!(newFragment instanceof FragmentIntro)) title.setTextColor(0xffeaeaea); title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); if (Build.VERSION.SDK_INT > 15) title.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL)); }//from w ww .j a va 2 s.com TextView desc = (TextView) parent.findViewById(R.id.description); if (desc != null) { desc.setTextColor(0xffe9e9e9); desc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15.5f); desc.setLineSpacing(1f, 1); //if (Build.VERSION.SDK_INT > 15) desc.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL)); } } }
From source file:org.akvo.caddisfly.ui.TypeListActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { final Activity activity = this; if (requestCode == PERMISSION_ALL) { // If request is cancelled, the result arrays are empty. boolean granted = false; for (int grantResult : grantResults) { if (grantResult != PERMISSION_GRANTED) { granted = false;/* w w w. j ava2s . c o m*/ break; } else { granted = true; } } if (granted) { startCalibration(); } else { String message = getString(R.string.cameraAndStoragePermissions); if (AppPreferences.useExternalCamera()) { message = getString(R.string.storagePermission); } Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) .setAction("SETTINGS", new View.OnClickListener() { @Override public void onClick(View view) { ApiUtil.startInstalledAppDetailsActivity(activity); } }); TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); snackbar.setActionTextColor(typedValue.data); View snackView = snackbar.getView(); TextView textView = (TextView) snackView.findViewById(android.support.design.R.id.snackbar_text); textView.setHeight(getResources().getDimensionPixelSize(R.dimen.snackBarHeight)); textView.setLineSpacing(0, SNACK_BAR_LINE_SPACING); textView.setTextColor(Color.WHITE); snackbar.show(); } } }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.instructions.InstructionDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_instruction_detail, container, false); Drawable instructionDrawable = AssetsManager.getImage(getActivity(), getArguments().getString(ARG_ITEM_IMAGE)); if (instructionDrawable != null) { ((ImageView) rootView.findViewById(R.id.image_illustration)).setImageDrawable(instructionDrawable); }/*from w w w . j ava 2s.c om*/ ArrayList<String> instructionText = getArguments().getStringArrayList(ARG_ITEM_TEXT); if (instructionText != null) { LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.layout_instructions); for (String instruction : instructionText) { TextView textView = new TextView(getActivity()); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.mediumTextSize)); textView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.activity_vertical_margin)); textView.setLineSpacing(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5.0f, getResources().getDisplayMetrics()), 1.0f); String text = instruction; if (instruction.contains("<!>")) { text = instruction.replaceAll("<!>", ""); textView.setTextColor(Color.RED); } else { textView.setTextColor(Color.DKGRAY); } if (instruction.contains("<b>")) { text = text.replaceAll("<b>", "").replaceAll("</b>", ""); textView.setTypeface(null, Typeface.BOLD); } else { textView.setTextColor(Color.DKGRAY); } Spanned spanned = StringUtil.getStringResourceByName(getContext(), text); if (!text.isEmpty()) { textView.append(spanned); linearLayout.addView(textView); } } } return rootView; }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.ui.BrandInfoActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { final Activity activity = this; if (requestCode == PERMISSION_ALL) { // If request is cancelled, the result arrays are empty. boolean granted = false; for (int grantResult : grantResults) { if (grantResult != PERMISSION_GRANTED) { granted = false;/*from ww w . j a v a 2s .c om*/ break; } else { granted = true; } } if (granted) { startCamera(); } else { Snackbar snackbar = Snackbar.make(coordinatorLayout, getString(R.string.cameraAndStoragePermissions), Snackbar.LENGTH_LONG) .setAction("SETTINGS", new View.OnClickListener() { @Override public void onClick(View view) { ApiUtil.startInstalledAppDetailsActivity(activity); } }); TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); snackbar.setActionTextColor(typedValue.data); View snackView = snackbar.getView(); TextView textView = (TextView) snackView.findViewById(android.support.design.R.id.snackbar_text); textView.setHeight(getResources().getDimensionPixelSize(R.dimen.snackBarHeight)); textView.setLineSpacing(0, SNACK_BAR_LINE_SPACING); textView.setTextColor(Color.WHITE); snackbar.show(); } } }
From source file:org.akvo.caddisfly.ui.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { final Activity activity = this; if (requestCode == PERMISSION_ALL) { // If request is cancelled, the result arrays are empty. boolean granted = false; for (int grantResult : grantResults) { if (grantResult != PERMISSION_GRANTED) { granted = false;/*from w w w . j a v a2 s. c om*/ break; } else { granted = true; } } if (granted) { startStripTest(); } else { String message = getString(R.string.storagePermission); if (AppPreferences.useExternalCamera()) { message = getString(R.string.storagePermission); } Snackbar snackbar = Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG) .setAction("SETTINGS", new View.OnClickListener() { @Override public void onClick(View view) { ApiUtil.startInstalledAppDetailsActivity(activity); } }); TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); snackbar.setActionTextColor(typedValue.data); View snackView = snackbar.getView(); TextView textView = (TextView) snackView.findViewById(android.support.design.R.id.snackbar_text); textView.setHeight(getResources().getDimensionPixelSize(R.dimen.snackBarHeight)); textView.setLineSpacing(0, SNACK_BAR_LINE_SPACING); textView.setTextColor(Color.WHITE); snackbar.show(); } } }
From source file:com.bitants.wally.fragments.MaterialDialogFragment.java
protected void setupViews(Context context) { if (titleResourceId != 0) { textViewTitle.setText(titleResourceId); } else if (titleString != null) { textViewTitle.setText(titleString); }/*from w ww .ja v a2 s.c o m*/ if (primaryColor != 0) { buttonPositive.setTextColor(primaryColor); } if (positiveButtonTextResourceId != 0) { buttonPositive.setText(positiveButtonTextResourceId); } if (negativeButtonTextResourceId != 0) { buttonNegative.setText(negativeButtonTextResourceId); } buttonNegative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (negativeButtonOnClickListener != null) { negativeButtonOnClickListener.onClick(null, 1); } dismiss(); } }); buttonPositive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (positiveButtonOnClickListener != null) { positiveButtonOnClickListener.onClick(null, 0); } dismiss(); } }); if (layoutResourceId != 0) { viewStub.setLayoutResource(layoutResourceId); viewStub.inflate(); } else if (message != null || messageResourceId != 0) { TextView textView = new TextView(context); if (messageResourceId != 0) { textView.setText(messageResourceId); } else { textView.setText(message); } textView.setTextColor(getResources().getColor(R.color.Black_Light)); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); textView.setLineSpacing(1f, 1.2f); scrollView.removeAllViews(); scrollView.addView(textView); } }
From source file:Main.java
public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor, int messageTextSize, CharSequence title, CharSequence message) { titleTv.setMinHeight(titleTextSize * 3); if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) { titleTv.setTextColor(titleColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize); titleTv.getPaint().setFakeBoldText(true); titleTv.setText(title);/*from w w w . j av a 2 s .co m*/ } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { titleTv.setTextColor(messageColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize); titleTv.setText(message); } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { SpannableString titleSs = new SpannableString(title + "\n" + message); titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleTv.setText(titleSs); titleTv.setLineSpacing(0.0f, 1.2f); } else { titleTv.setVisibility(View.GONE); } }
From source file:com.github.irshulx.Components.InputExtensions.java
public void setLineSpacing(TextView textView, float lineHeight) { int fontHeight = textView.getPaint().getFontMetricsInt(null); textView.setLineSpacing(Utilities.dpToPx(editorCore.getContext(), lineHeight) - fontHeight, 1); }
From source file:com.tooltip.Tooltip.java
private View getContentView(Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); int padding = (int) builder.mPadding; TextView textView = new TextView(builder.mContext); TextViewCompat.setTextAppearance(textView, builder.mTextAppearance); textView.setText(builder.mText);//from www . jav a2 s . c o m textView.setPadding(padding, padding, padding, padding); textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier); textView.setTypeface(builder.mTypeface, builder.mTextStyle); if (builder.mTextSize >= 0) { textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize); } if (builder.mTextColor != null) { textView.setTextColor(builder.mTextColor); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { textView.setBackground(drawable); } else { //noinspection deprecation textView.setBackgroundDrawable(drawable); } LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textView.setLayoutParams(textViewParams); mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) Util.dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(textView); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(textView); } mContentView.setOnClickListener(mClickListener); mContentView.setOnLongClickListener(mLongClickListener); if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }
From source file:com.zitech.framework.widget.SlidingTabs.java
/** * add text view type of tab//from ww w. j a v a 2 s. c o m * <p/> * you can set the text view attribute in here * * @param position position * @param title title */ private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title); tab.setGravity(Gravity.CENTER); // You can set the text view single line // tab.setSingleLine(); tab.setLineSpacing(5, 1.0f); addTab(position, tab); }