如何在我的textView的文字周圍製作黑線?例如上述圖像圍繞文字的黑線
Q
圍繞文字的黑線
2
A
回答
5
上擴展的TextView類。然後在onDraw中,首先使用黑色繪製文本,然後再次繪製,稍微小一些,並使用白色。爲了獲得額外的「正確性」,請將自定義屬性添加到XML以設置「線條」顏色。
public class myTextView extends TextView{
public myTextView (Context context) {
this(context, null);
}
public myTextView (Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public myTextView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// do extra initialisation and get attributes here
}
@Override
protected void onDraw(Canvas canvas) {
// draw first in black
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(20); // text size
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("My text", 50, 50, paint);
// draw again in white, slightly smaller
paint.setColor(Color.WHITE);
paint.setTextSize(18); // text size
canvas.drawText("My text", 50, 50, paint);
}
}
的代碼是不完整的,因爲它的硬編碼的顏色,大小和位置,但我希望這是足以讓你一起工作。您可以通過構造函數中的attrs從XML獲取文本大小和文本顏色,並將行顏色和寬度添加爲自定義屬性(在此處搜索或Google)。
+0
非常感謝你 –
+0
不客氣。 – Simon
4
0
描述一下添加到您的xml文件的字體:
android:shadowColor="#000000"
android:shadowDx="1.5"
android:shadowDy="1.3"
android:shadowRadius="1.6"
android:text="YOUR TEXT"
android:textColor="@color/white"
相關問題
- 1. 黑客圍繞IE
- 2. 圍繞文字環繞HTML
- 3. 圍繞固定分隔線圍繞文本
- 4. iPhone:圍繞圖像環繞文字
- 5. 圍繞圖片環繞文字IE
- 6. 圍繞圖像環繞文字
- 7. Flex 4 - 圍繞圖像環繞文字
- 8. 圍繞着浮動環繞文字
- 9. 圍繞圖像環繞文字
- 10. 圍繞文字環繞一個div
- 11. 圍繞EditFields的邊界 - 黑莓
- 12. 圍繞左下角div圍繞文本?
- 13. 圍繞相對位置div div圍繞文字
- 14. 圍繞兩行文字旁邊的一條線,引導
- 15. 圍繞線條的圓圈 - 崇高文字3
- 16. 文字環繞圖像周圍的
- 17. 圍繞圖像錯誤的Android文字
- 18. 圍繞編輯文字的邊框
- 19. 用Joomla圍繞Seblod中的元素圍繞文章文本
- 20. iphone石英畫線圍繞線條
- 21. 圍繞一個DIV中的所有數字圍繞SPAN
- 22. 圍繞文字換行不換行
- 23. 環繞文字圖像周圍(響應)
- 24. PHPWord - 在表格周圍環繞文字
- 25. 圍繞廣場圖像居中文字
- 26. 用css圍繞圓圈文字
- 27. 在DIV上和周圍環繞文字
- 28. AS3圍繞中心旋轉文字?
- 29. 圍繞span-chrome問題換行文字
- 30. 用文字圍繞雙引號圖片
我不明白,MS油漆? PhotoShop的?瘸子? –
嘗試在它後面放置一個黑色陰影:http://stackoverflow.com/questions/3182393/android-textview-outline-text – Ahmad
@DannyHong我認爲Max想勾勒出他的文字。 – Ahmad