设置边框和TextView的背景颜色边框、颜色、背景、TextView

由网友(上课觉觉)分享简介:我在XML中定义一个TextView,我想设置背景颜色和边框它。我的问题是,在XML我已经使用安卓背景设置边框的资源,所以我不能再使用它作为背景色。可有人请指引我正确的方向?Border.xml < XML版本=1.0编码=UTF-8&GT?;<形状的xmlns:机器人=htt​​p://schema...

我在XML中定义一个TextView,我想设置背景颜色和边框它。 我的问题是,在XML我已经使用安卓背景设置边框的资源,所以我不能再使用它作为背景色。 可有人请指引我正确的方向?

Border.xml

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:形状=矩形>
   [固体机器人:颜色=#FFFFFF/>
   <行程机器人:宽=1dip机器人:颜色=#7F000000/>
< /形状>
 

的TextView

 <的TextView
        机器人:ID =@ + ID / editor_title
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:背景=@可绘制/ title_border
        机器人:填充=5DP
        机器人:文本=@字符串/ editor_title
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>
 

解决方案 求助 EXCEL2003 把表格内的某一数字背景设为某种颜色

您应该创建一个XML绘制了这一点,这可以被设置为你的单身背景。这里是你想要(矩形用不同颜色的边框 - 有,如果你不希望替换梯度)。

这会在你的绘制文件夹:

 < XML版本=1.0编码=UTF-8&GT?;
<形状
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:形状=矩形>
    <行程机器人:宽=3DP机器人:颜色=@色/ blue_button_border/>
    <梯度
      机器人:startColor =@色/ gradient_end
      机器人:endColor =@色/ gradient_start
      机器人:角= -  90/>
< /形状>
 

I have a TextView defined in XML and i would like to set background color AND border to it. Problem i have is that in XML i already use android:background for setting border resource, so i can't use it once again for background color. Can someone please guide me to right direction?

Border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#ffffff" />
   <stroke android:width="1dip" android:color="#7F000000"/>
</shape>

TextView

<TextView
        android:id="@+id/editor_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/title_border"         
        android:padding="5dp"
        android:text="@string/editor_title"               
        android:textAppearance="?android:attr/textAppearanceMedium" />

解决方案

You should create a XML drawable for this, which can then be set as your single background. Here is what you are wanting (a rectangle with a different color border - replace gradient with if you don't want that).

This will go in your 'drawable' folder:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="3dp" android:color="@color/blue_button_border" />
    <gradient
      android:startColor="@color/gradient_end"
      android:endColor="@color/gradient_start"
      android:angle="-90" /> 
</shape>

阅读全文

相关推荐

最新文章