更改EditText的设计

时间:2017-06-21 12:12:14

标签: android android-edittext

我是Android开发的新手,最近开始使用android studio制作应用程序。

是否可以更改EditText组件的外观以及如何?

以下是我创建新内容时的默认外观:

http://imgur.com/eFWNIJb

这就是我想要实现的目标:

http://imgur.com/uwaOBi7

提前谢谢。

编辑:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.fivecore.nuqliati"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

3 个答案:

答案 0 :(得分:0)

Android浮动标签在Android设计支持库中引入,以在EditText上显示浮动标签。

将此库编译为我的朋友

compile 'com.android.support:design:26.+''

而不是在xml布局文件中添加此代码

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email Address" />

 </android.support.design.widget.TextInputLayout>

有关详情,请点击此处androidhive

答案 1 :(得分:0)

对于这种类型的设计,android提供了可以改变编辑文本外观的库

只使用此textview

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Email"
    android:textColorHint="#4233FF" />

别忘了将此依赖项添加到gradle

compile 'com.android.support:design:25.3.1'

答案 2 :(得分:0)

其中称为Android浮动标签,您必须使用TextInputLayout视图才能使用此库

  

compile&#39; com.android.support:design:25.3.1&#39;

你可以在视图布局中使用它

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="First Name"
        android:id="@+id/fname" />

 </android.support.design.widget.TextInputLayout>