Skip to content

Commit

Permalink
custom adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidregan committed Oct 28, 2019
1 parent 8057e62 commit 8d2eb83
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ protected void onCreate(Bundle savedInstanceState) {
//textView.setShowingChar(30);

textView.addShowMoreText("Continue");
textView.addShowLessText("Less");


}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>

<color name="black_50">#80000000</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
Expand Down Expand Up @@ -57,7 +59,10 @@ public ShowMoreTextView(Context context) {

public ShowMoreTextView(Context context, AttributeSet attrs) {
super(context, attrs);

showLess = context.getString(R.string.read_less);
showMore = context.getString(R.string.read_more);
showMoreTextColor = Color.parseColor("#80000000");
showLessTextColor = Color.parseColor("#80000000");
}

@Override
Expand Down Expand Up @@ -168,14 +173,15 @@ public void onClick(@Nullable View view) {
spannableString.setSpan(new ForegroundColorSpan(showMoreTextColor),
getText().length() - (dotdot.length() + showMore.length()),
getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), getText().length() - (dotdot.length() + showMore.length()),
getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

setMovementMethod(LinkMovementMethod.getInstance());
setText(spannableString, TextView.BufferType.SPANNABLE);
}

private void showLessButton() {

String text = getText() + dotdot + showLess;
String text = getText() + showLess;
SpannableString spannableString = new SpannableString(text);

spannableString.setSpan(new ClickableSpan() {
Expand All @@ -195,11 +201,13 @@ public void onClick(@Nullable View view) {

}
},
text.length() - (dotdot.length() + showLess.length()),
text.length() - showLess.length(),
text.length(), 0);

spannableString.setSpan(new ForegroundColorSpan(showLessTextColor),
text.length() - (dotdot.length() + showLess.length()),
text.length() - showLess.length(),
text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), text.length() - showLess.length(),
text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

setMovementMethod(LinkMovementMethod.getInstance());
Expand Down
2 changes: 2 additions & 0 deletions showmoretextview/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">ShowMoreTextView</string>
<string name="read_less">&#160;&#160;read less</string>
<string name="read_more">read more</string>
</resources>

0 comments on commit 8d2eb83

Please sign in to comment.