deano2390 / MaterialShowcaseView

A Material Design themed ShowcaseView for Android
Apache License 2.0
2.72k stars 526 forks source link

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

Open sandrocsimas opened 8 years ago

sandrocsimas commented 8 years ago
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...

turing-tech commented 8 years ago

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

sandrocsimas commented 8 years ago

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 commented 8 years ago

screenshot_20160319-204343 ![Uploading Screenshot_20160319-204354.png…]()

da1nerd commented 7 years ago

@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 commented 7 years ago

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

BernardoGui commented 4 years ago

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

}

`

ItzNotABug commented 3 years ago

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.