如何解决如何在AndroidJava中修整TextView?
我的主活动中包含以下代码:
LinearesLayout = (LinearLayout) findViewById(R.id.linearlayout);
TextView textView = new TextView(this);
textView.setBackgroundResource(R.color.colorPrimary);
LinearesLayout.addView(textView);
如何设置TextView的角为圆角?
解决方法
在res \ drawable文件夹-rounded_corners.xml
中创建XML文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff0000"/>
<corners android:radius="4dp" />
<padding
android:top="5dp"
android:left="5dp"
android:bottom="5dp"
android:right="5dp" />
</shape>
替换此行:
textView.setBackgroundResource(R.color.colorPrimary);
对此:
textView.setBackgroundResource(R.drawable.rounded_corners);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。