久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在android的編輯框中添加標簽

Label in a editbox in android(在android的編輯框中添加標簽)
本文介紹了在android的編輯框中添加標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的問題是,如何在 android 的 editBox 中放置標簽?

My question is, how to put a label in a editBox in android ?

例如,我想在聯系人選擇器的 editbox 中輸入To:",即使我按屏幕鍵盤上的退格鍵也不會被刪除.

Like for example, i want to put "To:" in editbox of a contact picker which will not get deleted even if I press backspace on the onscreen keyboard.

我嘗試使用 android:hint,但是當編輯框成為焦點或單擊時它會被刪除.

I tried with android:hint, but it gets deleted when the editBox is focus or clicked.

我嘗試了圖像,但看起來不太好.所以,我需要一種方法來實現這個標簽的東西.

I tried with image but it's not looking good. So, I need a method by which i can implement this label thing.

查看可視化圖

推薦答案

我給你兩個想法:

如果您只在幾個地方需要它,您可以使用 FrameLayout/merge 在您的 EditText 上添加一個 TextView.然后在編輯文本上使用填充,您可以使 TextView 看起來像是在 EditText內部".:

If you only need this in a couple of places, you can use a FrameLayout / merge to have a TextView over your EditText. Then using a padding on the edit text, you can make it seem like the TextView is "inside" the EditText. :

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp" >

        <requestFocus />
    </EditText>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingLeft="10dp"
        android:text="To : " />
</FrameLayout>

否則,您可以通過編寫自己的類來實現自己的 EditText 版本.這是一個基本示例,您需要對其進行一些調整:

Else you can inplement your own version of EditText, by writing your own Class. Here's a basic example, you'd need to tweak it a little :

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.EditText;

public class LabelledEditText extends EditText {

    public LabelledEditText(Context context) {
        super(context);
        mPaddingLeft = getPaddingLeft();
    }

    public LabelledEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaddingLeft = getPaddingLeft();
    }

    protected void onDraw(Canvas canvas) {
        TextPaint textPaint = getPaint();
        Rect size = new Rect();
        textPaint.getTextBounds(mLabel, 0, mLabel.length(), size);
        setPadding(mPaddingLeft + size.width(), getPaddingTop(), getPaddingRight(), getPaddingBottom());
        super.onDraw(canvas);

        canvas.drawText(mLabel, mPaddingLeft + size.left, size.bottom + getPaddingTop(), textPaint);
    }


    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private String mLabel = "To :  ";
    private int mPaddingLeft;

}

這篇關于在android的編輯框中添加標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 国产毛片毛片 | 欧美日韩国产一区二区三区 | 亚洲欧美在线一区 | 一区二区三区在线看 | 在线观看视频你懂得 | 精品久久久久久国产 | 国产欧美日韩综合精品一 | 91精品久久久久 | 在线视频一区二区 | 亚洲免费毛片 | 国产精品99一区二区 | 精品视频在线一区 | 日韩一区三区 | 精品99在线 | 二区中文 | 成人av片在线观看 | 午夜一区 | 在线视频一区二区 | 精品久久久网站 | 懂色中文一区二区三区在线视频 | 国产精品成人免费 | 亚洲精品一区二区三区中文字幕 | 黄色免费网站在线看 | 99久久久无码国产精品 | 日本在线视频一区二区 | 国产一级片在线播放 | 国产精品成人久久久久 | 国产精品久久久久久网站 | 中文字幕一区在线 | 欧美中文字幕在线观看 | 国产黄色在线观看 | 久久精品国产99国产 | 日韩欧美国产精品 | 一级视频在线免费观看 | 欧美日韩精品 | av看片网| 国产成人精品免费 | 中文字幕av一区 | 自拍视频网 | 亚洲一区二区三区免费在线观看 | 91在线色视频|