【问题标题】:Android: Making EditText similar to Chrome's URL boxAndroid:使 EditText 类似于 Chrome 的 URL 框
【发布时间】:2012-10-22 00:54:11
【问题描述】:

我正在为学校的作业制作聊天应用程序。

在我看来,Android 中默认的 EditText 看起来不太好。我想让它看起来像 Android 的 Chrome 中的 URL 框:

我在其他应用程序中看到过这种设计,例如Catch Notes(看起来很漂亮)。

那么,是否有任何内置选项可以更改 EditText 或者我们必须从头开始绘制它?谁能给个链接?我试着用谷歌搜索它,但我不知道正确的术语

谢谢

【问题讨论】:

    标签: android textbox android-edittext


    【解决方案1】:

    你可以通过edittext background transparent来实现。

    所以把你的图片放在你的布局的背景中,并在里面放一个edittext。并使edittext透明化..

    或 试试这个

    <EditText
            android:id="@+id/tracknumbertxt"
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_toLeftOf="@+id/info"
            android:background="@drawable/enter_tracking_no"
            android:ems="10"
            android:hint="Enter Tracking No."
            android:paddingLeft="30dp"
            android:inputType="text"
            android:imeOptions="actionGo"
    
            android:singleLine="true" >
    
        </EditText>
    

    这里我已经分配了填充左侧..

    所以根据您的设计,您必须设置 paddingRight 属性而不是 paddingLeft..

    【讨论】:

    • 谢谢,但是 imeOptions 是干什么用的?好像没什么效果
    【解决方案2】:

    盲目使用下面的布局样式.. 您将准备好布局。只需更换按钮背景即可。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:background="@android:color/darker_gray"
        android:padding="5dip"
        android:gravity="center">
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:gravity="center"
            android:padding="5dip">
            <EditText android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="Type URL"
                android:layout_weight="1"
                android:background="@android:color/transparent"/>
            <Button android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Refresh"/>
        </LinearLayout>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn1"/>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn2"/>
    </LinearLayout>
    

    【讨论】:

    • 背景透明似乎是实现这一点的最简单方法,尽管它并不完全相同,但足够接近。谢谢
    【解决方案3】:

    SDK 本身没有任何东西可以使它看起来像这样。 (也许如果您将使用仅限于某个版本的操作系统,那么您可以使用该版本的默认样式,但这并不是一个真正可行的解决方案)

    您需要创建一个图像以用作 EditText 的背景,以使其看起来像您想要的那样。文本框和类似内容的最佳选择是使用9-patchimage,或创建layer-listXML 文件并以这种方式描述您的设计。无论哪种方式,该文件都将放在项目的 res/drawable 文件夹中,您可以将其设置为背景,如下所示:

    <EditText android:id="@+id/et_whatever"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        background="@drawable/YOUR_FILE_NAME" />
    

    【讨论】:

    • 是的,我只限制 ICS+。所以我想我对背景没问题:透明的 9 补丁图像看起来很有趣,我有时会尝试一下
    猜你喜欢
    • 1970-01-01
    • 2012-12-05
    • 2014-11-02
    • 1970-01-01
    • 2011-12-08
    • 2010-12-13
    • 1970-01-01
    • 2023-03-07
    • 2018-05-12
    相关资源
    最近更新 更多