Skip to content

Commit bc8a44b

Browse files
authored
Update README.md
1 parent ddd06e1 commit bc8a44b

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,52 @@ an android drawable object which contains text and image
1818

1919
* 然后就可以直接在代码中使用就可以了
2020

21+
## Api的简单介绍
22+
23+
```java
24+
25+
/**
26+
* 实例化一个同时包含文字和图片的drawable
27+
*/
28+
TextWithImageDrawable textWithImageDrawable = new TextWithImageDrawable(thisActivity);
29+
/**
30+
* 设置drawable里的文字
31+
*/
32+
textWithImageDrawable.setText(text);
33+
/**
34+
* 设置drawable里的图像资源
35+
*/
36+
textWithImageDrawable.setImageRes(leftMenuIconResId);
37+
/**
38+
* 设置drawable中文字的大小,注意此处的单位是sp
39+
*/
40+
textWithImageDrawable.setTextSize(16);
41+
/**
42+
* 设置文字的颜色
43+
*/
44+
textWithImageDrawable.setTextColor(getResources().getColor(R.color.text_color_white));
45+
/**
46+
* 设置文字和图像之前的间隔,单位是px
47+
*/
48+
textWithImageDrawable.setImagePadding(DensityUtils.dip2px(5));
49+
/**
50+
* 设置此drawable的左边填充大小,单位px
51+
*/
52+
textWithImageDrawable.setPaddingLeft(DensityUtils.dip2px(8));
53+
/**
54+
* 设置此drawable上方填充大小,单位px
55+
*/
56+
textWithImageDrawable.setPaddingTop(DensityUtils.dip2px(6));
57+
/**
58+
* 设置此drawable的最大文字限制长度
59+
*/
60+
textWithImageDrawable.setMaxTextLength(3);
61+
/**
62+
* 设置图像和文字的相对位置,此处设置的是图像在文字右边显示
63+
*/
64+
textWithImageDrawable.setImagePosition(TextWithImageDrawable.Position.RIGHT);
65+
66+
```
2167
## 使用示例:
2268

2369
```java

0 commit comments

Comments
 (0)