【发布时间】:2014-03-08 19:45:30
【问题描述】:
我想为我的 TextView 创建一个背景,使其看起来完全像这个(黄色框)。
创建图像后,如何设置电视的背景?
谢谢!
【问题讨论】:
我想为我的 TextView 创建一个背景,使其看起来完全像这个(黄色框)。
创建图像后,如何设置电视的背景?
谢谢!
【问题讨论】:
【讨论】:
或者你可以创建一个可绘制的形状。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/Yellow" />
<stroke android:width="@dimen/" android:color="@color/"/>
<corners android:radius="@dimen/"/>
<gradient
android:startColor="@color/"
android:centerColor="@color/"
android:endColor="@color/"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="100"
android:type="linear" />
</shape>
【讨论】:
也可以使用 shape 属性来完成。
我使用以下内容为自己创建了一个类似的。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" /> //This should be the yellow color you want
<corners android:radius="5dp" /> //for rounded corners
<stroke
android:width="2dp"
android:color="@color/color_dark_blue" /> //for border if you wish any
</shape>
在 drawable 中将其创建为 xml 文件(比如 myTextViewBg.xml)。
然后将其作为背景添加到您的 TextView 中,
yourTextView:background="@drawable/myTextViewBg.xml"
【讨论】:
您可以设置文本视图的背景
android:background="@drawable/myResouce"
或使用java
mTextView.setBackgroundResource(R.drawable.myResouce);
但在您的情况下,创建一个相对布局,然后在其中放置一个 imageView 和 Textview 并根据您的视图进行调整。
在imageView 中使用您在问题中的图片,希望文字会发生变化。在textView 中使用可变文本。你也可以务实地改变它。
【讨论】: