关于android中EditText边框的问题 下划线

摘要:
方法1:将edittext的样式设置为?如果没有,我会看到123456789101112131415161718192021223242526272829303132333435363738383839渲染:方法2:自定义Android控件编辑文本边框背景刘志超博客程序Android自定义Android控件Edit文本边框背景postedinAndrodon2011/06/02byliuzc当我们设计Android应用程序界面时,为了统一界面样式,我们需要自定义一些控件。例如,我们的应用程序采用蓝色风格,但Android的EditTex TControl在获得焦点后显示黄色边框背景。˃˃selectorxmlns:android=“http://schemas.android.com/apk/res/android“˃然后在values文件夹下创建一个新的style.xml文件,内容如下:˂?

方法1

 

将edittext的style设置成?android:attr/textViewStyle 取消掉默认的样式,在设置background为@null

接下来就是一个空空的edittext了, 在两个edittext中间加一个view,设置background为灰色,宽度match_parent,高度2dip看看。

如果可以了就采纳吧。不行的话我再看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray">
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@android:color/white"
        android:orientation="vertical">
 
        <EditText
            style="?android:attr/textViewStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="输入用户名"
            android:paddingBottom="5dip"
            android:paddingTop="5dip"/>
 
        <View
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="@android:color/darker_gray"/>
 
        <EditText
            style="?android:attr/textViewStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="输入密码"
            android:inputType="textPassword"
            android:paddingBottom="5dip"
            android:paddingTop="5dip"/>
    </LinearLayout>
 
</RelativeLayout>

效果图:

关于android中EditText边框的问题 下划线第1张

方法2:

自定义android控件EditText边框背景

柳志超博客 » Program » Andriod » 自定义android控件EditText边框背景

posted in Andriod on 2011/06/02 by 

在我们进行Android应用界面设计和时候,为了界面风格的统一,我们需要对一些控件进行自定义。比如我们的应用采用的蓝色风格,但是android的EditText控制获得焦点后显示的却是黄色的边框背景。那么如何让EditText在获得焦点的时候显示的是我们自定义的蓝色的背景呢?

首先准备两张图片,一张是EditText获得焦点后的边框背景,一张是没有获得焦点时的背景,注意制作成9.png样式的图片,然后在drawable里添加一个selector_edittext_bg.xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/edit_pressed" android:state_focused="true"/>
    <item android:drawable="@drawable/edit_normal"/>

</selector>

然后在values文件夹下新建一个style.xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="my_edittext_style" parent="@android:style/Widget.EditText">
        <item name="android:background">@drawable/selector_edittext_bg</item>
    </style>

</resources>

最后在EditTex上使用我们新建的样式就可以了:

<EditText
            android:id="@+id/v_value"
            style="@style/my_edittext_style"
            android:layout_width="0.0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/edit_key"
            android:imeOptions="actionDone"
            android:inputType="" />

关于android中EditText边框的问题 下划线第2张

 方法3

是重写的onDraw()方法

免责声明:文章转载自《关于android中EditText边框的问题 下划线》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇在WPF中集成OpenTK关于D3D11,你必须了解的几件事情(一)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

AndroidManifest.xml文件详解(uses-feature)

http://blog.csdn.net/think_soft/article/details/7596796 语法(SYNTAX): <uses-featureandroid:name="string"              android:required=["true" | "false"]               android:gl...

h5红包雨

现在很多活动中都会有一些小游戏,比如抽奖轮盘,红包雨等等,今天心血来潮写了一个粗糙的红包雨 <div class="content"> <div class="bg_box"> <img src="./image/bg.jpg"/> </div> </div>...

Android怎样设置圆角button

1. 在res文件夹下的drawable文件夹下新建shape.xml文件 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectan...

JS === 实现简易调色板

<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> *{margin:0;padding:0;} .box{ 500px;height: 400px;...

CSS伪元素before和after

今天发现很多国外的网站和框架设计都用到了before和after,之前使用的比较少,今天试了下觉得还是很有意思的~ 说明 1. :before 和 :after将在内容元素的前后插入额外的元素;:before将会在内容之前“添加”一个元素而:after将会在内容后“添加”一个元素。在它们之中添加内容我们可以使用content属性。 2. :before 和...

CSS3实现10种Loading效果(转)

CSS3实现10种Loading效果 原文地址:http://www.cnblogs.com/jr1993/p/4622039.html 昨晚用CSS3实现了几种常见的Loading效果,虽然很简单,但还是分享一下,顺便也当是做做笔记…… 第1种效果: 代码如下: <div class="loading"> <sp...