Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaqiulei committed Nov 30, 2016
1 parent b12de61 commit 74bb997
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 95 deletions.
165 changes: 87 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ dependencies {
}
```
# Demo
![Demo](image/device-2016-11-30-233151.png)
![Demo](image/device-2016-11-30-233217.png)
```java
public class MainActivity extends AppCompatActivity {

Expand All @@ -45,93 +46,101 @@ public class MainActivity extends AppCompatActivity {

TextView textView = (TextView) findViewById(R.id.textview);

TextStyleItem one = new TextStyleItem("http://www.baidu.com")
.setTextColor(Color.parseColor("#f00f0f"))
.setClickListener(new TextStyleItem.OnClickListener() {

int textColor = Color.parseColor("#ff6000");
new StyleBuilder()
.addTextStyle("Test click.").textColor(Color.parseColor("#ff0000"))
.click(new ClickListener() {
@Override
public void onClick(String clickedText) {
Toast.makeText(MainActivity.this, "onClick", Toast.LENGTH_SHORT).show();
public void click(String text) {
Toast.makeText(MainActivity.this, "click", Toast.LENGTH_SHORT).show();
}
});

})
.commit().newLine().newLine()

TextStyleItem two = new TextStyleItem("Liushuixiaoxia")
.setTextColor(Color.parseColor("#f0aa0f"))
.setLongClickListener(new TextStyleItem.OnLongClickListener() {
.addTextStyle("Test long click.").textColor(Color.parseColor("#ff0000"))
.longClick(new LongClickListener() {
@Override
public void onLongClick(String clickedText) {
Toast.makeText(MainActivity.this, "onLongClick", Toast.LENGTH_SHORT).show();
public void longClick(String text) {
Toast.makeText(MainActivity.this, "longClick", Toast.LENGTH_SHORT).show();
}
});
})
.commit().newLine().newLine()

TextStyleItem three = new TextStyleItem("TestBackground")
.setTextColor(Color.WHITE)
.setBackgroundColor(Color.BLACK)
.setTextSize(Utils.dip2px(this, 20))
.setLongClickListener(new TextStyleItem.OnLongClickListener() {
.addTextStyle("Test background.").textColor(Color.GREEN).backgroundColor(Color.BLUE)
.textSize(Utils.dip2px(this, 20))
.longClick(new LongClickListener() {
@Override
public void onLongClick(String clickedText) {
Toast.makeText(MainActivity.this, "onLongClick", Toast.LENGTH_SHORT).show();
public void longClick(String text) {
Toast.makeText(MainActivity.this, "longClick", Toast.LENGTH_SHORT).show();
}
});
})
.commit().newLine().newLine()

new StyleBuilder()
.addStyleItem(one)
.newLine()
.addStyleItem(two)
.newLine()
.addStyleItem(three)
.newLine()
.addStyleItem(new TextStyleItem("http://www.google.com").setUnderLined(true))
.newLine()
.addStyleItem(new TextStyleItem("http://www.google.com").setStrikethrough(true))
.newLine()
.text("TEST")
.addStyleItem(
new TextStyleItem("subscript")
.setSubscript(true)
.setTextColor(Color.parseColor("#f00f0f"))
)
.addStyleItem(
new TextStyleItem("superscript")
.setSuperscript(true)
.setTextColor(Color.parseColor("#f00f0f"))
)
.newLine()
.addStyleItem(new TextStyleItem("Style").setTypeFaceStyle(Typeface.BOLD))
.newLine()
.addStyleItem(new TextStyleItem("image").setIconRes(R.drawable.ic1))
.addStyleItem(new TextStyleItem("image").setIconDrawable(getResources().getDrawable(R.drawable.ic2)))
.addStyleItem(
new TextStyleItem("image")
.setIconBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic3))
)
.newLine()
.text("流水不腐")
.addStyleItem(
new ImageStytleItem("流水不腐")
.setImageRes(R.drawable.image_drawable)
.setTextColor(Color.GREEN)
// .setTextSize(Utils.dip2px(this, 30))
)
.newLine()
.text("abcdefghijklmn")
.addStyleItem(
new ImageStytleItem("abcdefghijklmn")
.setImageRes(R.drawable.ic_launcher)
.setTextColor(Color.WHITE)
)
.newLine()
.show(textView);
}
}
```
.addTextStyle("Test under line. http://www.google.com").underLined(true).textColor(Color.BLUE)
.commit().newLine().newLine()

.addTextStyle("Test strikethrough. http://www.google.com").strikethrough(true).textColor(Color.BLUE)
.commit().newLine().newLine()

.addTextStyle("Test subscript.").subscript(true).textColor(Color.GREEN)
.commit().newLine().newLine()

![Demo](image/device-2015-08-02-154539.png)
.addTextStyle("Test superscript.").superscript(true).textColor(Color.GREEN)
.commit().newLine().newLine()

.addTextStyle("Test type face.").typeFaceStyle(Typeface.BOLD).textColor(Color.BLACK)
.commit().newLine().newLine()

![Demo](image/device-2015-08-02-154611.png)
.text("Test image1.")
.addTextStyle("image").iconRes(R.drawable.ic1)
.commit().newLine().newLine()

![Icon](image/device-2015-08-03-001419.png)
.text("Test image2.")
.addTextStyle("image").iconDrawable(getResources().getDrawable(R.drawable.ic2))
.commit().newLine().newLine()

![Drawable](image/device-2015-08-04-110307.png)
.text("Test image3.")
.addTextStyle("image").iconBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic3))
.commit().newLine().newLine()

.text("Test text and image.")
.addImageStyle("流水不腐").imageRes(R.drawable.image_drawable).textColor(Color.BLUE)
.commit().newLine().newLine()

.addImageStyle("Test text and image.").imageRes(R.drawable.ic_launcher).textColor(Color.BLACK)
.commit().newLine().newLine()

.addTextStyle("call").iconRes(R.drawable.ic_call).commit()
.text(" 夏先生 ")
.addTextStyle("13812345678").underLined(true).textColor(Color.BLUE)
.commit()
.newLine().newLine()

.text("可口可乐 x1 ").addTextStyle(" ¥4").textColor(Color.RED).commit().newLine()
.text("鱼香肉丝 x1 ").addTextStyle(" ¥10").textColor(Color.RED).commit().newLine()
.text("米饭 x1 ").addTextStyle(" ¥2").textColor(Color.RED).commit().newLine()
.newLine().newLine()

.addImageStyle(" 水果 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.text(" ")
.addImageStyle(" 肉类 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.text(" ")
.addImageStyle(" 蔬菜 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.newLine().newLine()


.addTextStyle("黄金咸鸭蛋").textSize(Utils.dip2px(this, 16)).textColor(Color.BLACK).commit().newLine()
.addTextStyle("4.7分").textColor(textColor).commit()
.addTextStyle(" 已售1000份").textColor(Color.GRAY).commit().newLine()
.addTextStyle("").textSize(Utils.dip2px(this, 12)).textColor(textColor).commit()
.addTextStyle("100 ").textSize(Utils.dip2px(this, 14)).textColor(textColor).commit()
.addTextStyle(" 110 ").textSize(Utils.dip2px(this, 13)).strikethrough(true).textColor(Color.GRAY)
.commit().newLine()


.show(textView);

}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
TextView textView = (TextView) findViewById(R.id.textview);


int textColor = Color.parseColor("#ff6000");
new StyleBuilder()
.addTextStyle("Test click.").textColor(Color.parseColor("#ff0000"))
.click(new ClickListener() {
Expand Down Expand Up @@ -86,6 +87,35 @@ public void longClick(String text) {
.addImageStyle("Test text and image.").imageRes(R.drawable.ic_launcher).textColor(Color.BLACK)
.commit().newLine().newLine()

.addTextStyle("call").iconRes(R.drawable.ic_call).commit()
.text(" 夏先生 ")
.addTextStyle("13812345678").underLined(true).textColor(Color.BLUE)
.commit()
.newLine().newLine()

.text("可口可乐 x1 ").addTextStyle(" ¥4").textColor(Color.RED).commit().newLine()
.text("鱼香肉丝 x1 ").addTextStyle(" ¥10").textColor(Color.RED).commit().newLine()
.text("米饭 x1 ").addTextStyle(" ¥2").textColor(Color.RED).commit().newLine()
.newLine().newLine()

.addImageStyle(" 水果 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.text(" ")
.addImageStyle(" 肉类 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.text(" ")
.addImageStyle(" 蔬菜 ").imageRes(R.drawable.tag_bg).textColor(Color.WHITE).commit()
.newLine().newLine()


.addTextStyle("黄金咸鸭蛋").textSize(Utils.dip2px(this, 16)).textColor(Color.BLACK).commit().newLine()
.addTextStyle("4.7分").textColor(textColor).commit()
.addTextStyle(" 已售1000份").textColor(Color.GRAY).commit().newLine()
.addTextStyle("¥").textSize(Utils.dip2px(this, 12)).textColor(textColor).commit()
.addTextStyle("100 ").textSize(Utils.dip2px(this, 14)).textColor(textColor).commit()
.addTextStyle(" 110 ").textSize(Utils.dip2px(this, 13)).strikethrough(true).textColor(Color.GRAY)
.commit().newLine()


.show(textView);

}
}
Binary file added app/src/main/res/drawable-xhdpi/ic_call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/tag_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<corners android:radius="15dp" />
<solid android:color="#00f" />
<stroke
android:width="1dp"
android:color="#00f" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
28 changes: 12 additions & 16 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
Binary file added image/device-2016-11-30-233151.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/device-2016-11-30-233217.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public SpannableString makeSpannableString(Context context) {
iconDrawable.draw(canvas);
}
if (iconBitmap != null) {
spannableString.setSpan(new ImageSpan(iconBitmap), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new ImageSpan(context, iconBitmap), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

return spannableString;
Expand Down

0 comments on commit 74bb997

Please sign in to comment.