0

丸みを帯びた EditText を作ろうとしました。main.xml のグラフィカル レイアウトでうまく表示されます。しかし、AVD を起動すると、まだ正方形です。コードは次のとおりです。

<EditText
        android:id="@+id/et"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:hint="Enter a #hashtag or keyword"
        android:textColor="#000000"
        android:drawableLeft="@drawable/magnifier"
        android:background="@drawable/rounded_edittext"
        android:textSize="16dp" >
        <requestFocus />
    </EditText> 
<!-- res/drawable/rounded_edittext.xml -->     <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners
    android:bottomLeftRadius="15dp"
    android:bottomRightRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp" />

4

2 に答える 2

2

これは丸みを帯びた編集テキストで、クリックの状態でも動作を変更します。単純に xml を使用します。

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_states.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
     android:state_pressed="true" 
     android:state_enabled="true"
        android:drawable="@drawable/rounded_focused" />
    <item 
     android:state_focused="true" 
     android:state_enabled="true"
        android:drawable="@drawable/rounded_focused" />
    <item 
     android:state_enabled="true"
        android:drawable="@drawable/rounded_edittext" />
</selector>

通常の丸め編集テキスト:

<?xml version="1.0" encoding="utf-8"?>
<!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#FFFFFF"/>
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

押された、フォーカスされた編集テキスト

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_focused.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#FFFFFF"/>
 <stroke android:width="2dp" android:color="#FF0000" />
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

そして...今、EditTextは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<EditText  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:background="@drawable/rounded_edittext_states"
    android:padding="5dip"/>
</LinearLayout>

私はこのレイアウトを使用してテストしましたが、複数のラウンド編集テキストでも機能します:

これは私が使用するレイアウトです

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/et"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_edittext"
        android:drawableLeft="@drawable/ic_launcher"
        android:hint="Enter a Login"
        android:textColor="#000000"
        android:textSize="16dp"
        android:padding="5dp">
        <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/et2"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et"
            android:layout_marginTop="14dp"
            android:background="@drawable/rounded_edittext"
            android:drawableLeft="@drawable/ic_launcher"
            android:ems="10"
            android:hint="Enter a Password"
            android:padding="5dp"
            android:textColor="#000000"
            android:textSize="16dp" />

</RelativeLayout>

これは、エミュレーターでの結果のスクリーン キャプチャです。

ここに画像の説明を入力

于 2012-06-01T18:47:07.913 に答える
0

// I feel that your rounded_edittext.xml is wrong.

can you remove this 2 lines

android:padding="10dp"
android:shape="rectangle"

//Or you can use myshape.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FAFFFA"/>    

    <corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" 
     android:topLeftRadius="15dp" android:topRightRadius="15dp"/>

 <stroke android:width="3dp" android:color="#C3C3C3"/> 

</shape>
于 2012-06-01T18:55:01.423 に答える