Tạo XML gọi border.xml trong thư mục drawable như sau:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
sau đó thêm này để bố trí tuyến tính như backgound như thế này:
android:background="@drawable/border"
lập trình
TitleLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.border))
CHỈNH SỬA:
Kể từ Jelly Bean, phương pháp này (setBackgroundDrawable đã bị phản đối), vì vậy nhưng bạn phải sử dụng cái này:
TitleLayout.setBackground(getResources().getDrawable(R.drawable.border));
hy vọng sự giúp đỡ này.
Bạn nên chấp nhận câu trả lời Sjoerd Van Den Berg. :-) – Alex