Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sandrocsimas opened this issue Mar 19, 2016 · 7 comments
Open

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

sandrocsimas opened this issue Mar 19, 2016 · 7 comments

Comments

@sandrocsimas
Copy link

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...

@sandrocsimas sandrocsimas changed the title When you set the title, the content text is invible. When you set the title, the content text is transparent. Mar 19, 2016
@turing-tech
Copy link
Contributor

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

@sandrocsimas
Copy link
Author

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

@sandrocsimas
Copy link
Author

screenshot_20160319-204343
Uploading Screenshot_20160319-204354.png…

@da1nerd
Copy link

da1nerd commented Feb 9, 2017

@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!

@noordawod
Copy link
Contributor

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

@BernardoGui
Copy link

This can be solve via reflection like described here: #7 (comment)
`

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) {
    
}

`

@ItzNotABug
Copy link

ItzNotABug commented Feb 16, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants