MaterialShowcaseView icon indicating copy to clipboard operation
MaterialShowcaseView copied to clipboard

When you set the title, the content text is transparent.

Open sandrosimas opened this issue 10 years ago • 7 comments

private void setTitleText(CharSequence contentText) {
    if(this.mTitleTextView != null && !contentText.equals("")) {
        // THIS LINE SHOULD NOT EXIST
        this.mContentTextView.setAlpha(0.5F);
        this.mTitleTextView.setText(contentText);
    }
}

Why this code sets the mContextTextView alpha to 0.5?

MaterialShowcaseView.Builder builder = new MaterialShowcaseView.Builder(activity);
builder.setTarget(view);
builder.setTitleText(titleResource);
builder.setContentText(detailResource);
builder.setContentTextColor(android.R.color.white);
builder.setDismissText(R.string.showcase_got_it);
builder.setDismissOnTouch(false);
builder.setDelay(Constants.SHOWCASE_SHOW_DELAY);
builder.setMaskColour(ContextCompat.getColor(activity, R.color.primary_showcase));
builder.singleUse(singleUseId);

Setting the content text color does not solve the problem...

sandrosimas avatar Mar 19 '16 22:03 sandrosimas

This was a stylistic choice to draw attention to the title by reducing the colour of the content.

turing-tech avatar Mar 19 '16 23:03 turing-tech

Yes, but the user can set this in setContentTextColor, setting a transparent color. As you said, it should be a choice and i didn't like the way it was. =( When i set the content text color to WHITE, it was very bad to read, depending the colors you use as your background. Furthermore, i think its bad practice to change the contentText inside the setTitleText method. This is not clear to user. See my PR: #85

sandrosimas avatar Mar 19 '16 23:03 sandrosimas

screenshot_20160319-204343 Uploading Screenshot_20160319-204354.png…

sandrosimas avatar Mar 19 '16 23:03 sandrosimas

@sandro-csimas has a very valid point. It is not intuitive to change the content style based on the title text. Doing so removes too much control from the developer. Now if I want to have full control over the text I'll have to use Spannables with line breaks, set that as the content text and avoid setting the title all together which is a very cumbersome solution to this issue.

All that being said. I'm loving this library. Thanks!

da1nerd avatar Feb 09 '17 06:02 da1nerd

Agree that this should NOT exist in the library, but offloaded to the developer. Opacity should not change.

noordawod avatar Feb 10 '17 14:02 noordawod

This can be solve via reflection like described here: https://github.com/deano2390/MaterialShowcaseView/issues/7#issue-101426494 `

MaterialShowcaseView showcaseView = builder.build();
Field field = null;
try {
    field = MaterialShowcaseView.class.getDeclaredField("mContentTextView");
    field.setAccessible(true);
    TextView textView = (TextView)field.get(showcaseView);
    textView.setAlpha(1.0f);
} catch (NoSuchFieldException e) {

} catch (IllegalAccessException e) {
    
}

`

BernardoGui avatar Feb 13 '20 20:02 BernardoGui

Without Reflection, you can use SpannableString to the contentText directly.
Example:

    // Not a very good way
    private fun getShowcaseContent(): SpannableString {
        val title = "New Feature! \n\n"
        val content = "Check out this awesome new feature, blah blah blah! 🥳"
        val spannableString = SpannableString(title + content)
        // 1.5f for title i.e. default text size * 1.5f
        spannableString.setSpan(RelativeSizeSpan(1.5f), 0, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        // 0.85f for content i.e. default text size * 0.85f, smaller than the title
        spannableString.setSpan(RelativeSizeSpan(0.85f), title.length + 1, (title + content).length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        return spannableString
    }

Usage:

    MaterialShowcaseView.Builder(this@Activity)
                .setTarget(view)
                // remember to set ONLY the CONTENT
                .setContentText(getShowcaseContent())
                // I don't need the dismiss button, so...
                .setDismissText("")
                .setTargetTouchable(true)
                .withCircleShape()
                .setDelay(250)
                .setDismissOnTargetTouch(true)
                .singleUse("show_case")
                .show()

This should fix the alpha as well as the Big title font issue on content if the title is used.

ItzNotABug avatar Feb 16 '21 06:02 ItzNotABug