How to embed a View (with Buttons, etc.) inside an EditText?

后端 未结 3 1303
我在风中等你
我在风中等你 2021-02-06 05:27

I\'m trying to figure out how to embed things, other than Drawables, inside an EditText widget. Specifically the example I\'m thinking of is from the Google Buzz widget

相关标签:
3条回答
  • 2021-02-06 05:46

    The EditText + Button + ... it's a FrameLayout with the EditText with fill_parent and the Buttons with layout_gravitiy:"bottom". Something like this:

    <?xml version="1.0" encoding="utf-8"?> <!-- Main Layout (may be relative or whatever --> <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <!-- Layout for edittext and button -->
        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
    
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:lines="5"/>
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_margin="5dip"
                android:text="Overflow"/>
    
        </FrameLayout>
    
        <!-- More layouts ..... -->   </RelativeLayout>
    
    0 讨论(0)
  • 2021-02-06 05:57

    you can use frame layout for embed Button in EditText,here i give sample code for embed TextView in EditText,just change the TextView as Button

    <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="40px"
            android:layout_y="35px"
            >        
    
        <EditText android:id="@+id/twt_post_content" android:layout_gravity="center_vertical"
            android:layout_width="320dp" android:layout_height="140dp"
            android:paddingTop="5dp" android:imeOptions="actionDone"
            android:gravity="left" android:focusableInTouchMode="true"
            android:maxLength="140" android:ellipsize="end" />
                <TextView
                    android:text="123" 
                    android:paddingLeft="270dp"      
                    android:paddingTop="100dp"   
                    android:layout_alignParentRight="true"
                    android:id="@+id/twt_content_count"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"              
                    android:textColor="@color/red"
                    android:layout_gravity="center"              
                    android:background="@color/transparent"/>    
                    </FrameLayout>        
    
    0 讨论(0)
  • 2021-02-06 05:59

    I think that what they have done here is create a background for their layout that looks like an EditText. Then they added an EditText with the background turned off and come Buttons.

    0 讨论(0)
提交回复
热议问题