Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中创建自定义文本视图背景?_Android_Textview - Fatal编程技术网

如何在Android中创建自定义文本视图背景?

如何在Android中创建自定义文本视图背景?,android,textview,Android,Textview,我想为我的文本视图创建一个与此完全相同的背景(黄色框)。 创建图像后,如何设置电视的背景 谢谢 为此,您可以创建简单的图像。然后换成九块 将背景设置为可绘制的 九面片图像示例 也可以使用“形状”属性来完成 我用下面的代码为自己创建了一个类似的 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:pad

我想为我的文本视图创建一个与此完全相同的背景(黄色框)。

创建图像后,如何设置电视的背景


谢谢

为此,您可以创建简单的图像。然后换成九块

将背景设置为可绘制的

九面片图像示例


也可以使用“形状”属性来完成

我用下面的代码为自己创建了一个类似的

<?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>

或者您可以创建一个可绘制的形状

<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>

您可以设置文本视图的背景
android:background=“@drawable/myresource”
或者使用java
mTextView.setBackgroundResource(R.drawable.myresource)

但在您的情况下,创建一个相对布局,然后将imageView和Textview放入其中,并根据您的视图进行调整

imageView
中,使用您在问题中希望更改的图像。在
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>