18

このようにレイアウトの周りに境界線を作ろうとしています

丸みを帯びた境界線を持つ 2 つのテキスト領域

しかし、私がしようとしているのは、レイアウトの色を変更することだけです。国境を作らない。

私のコードは

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

<stroke android:width="1dp"

        android:color="#eedfcc"
        android:background="#000080"/>

<corners android:bottomRightRadius="20dp"
         android:bottomLeftRadius="20dp" 
         android:topLeftRadius="10dp"
         android:topRightRadius="8dp"/> 
</shape>

なぜうまくいかないのですか?

4

4 に答える 4

62

これを試して:

ステップ 1 :layout_border.xmlプロジェクトのドローアブル ディレクトリ (res/drawable/layout_border.xml)にファイルを作成します。

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" />
    <corners android:radius="10dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

ステップ2:

<EditText 
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_border"
     /> 
于 2012-07-03T06:17:28.007 に答える
3

ファイル「res/drawable / my_border.xml」を作成し、形状を定義します。

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="4dp" android:color="#FF00FF00" />
    <solid android:color="#ffffff" />
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

次に、これをレイアウトタグ内の背景として追加します。

android:background="@drawable/my_border"
于 2012-07-03T06:27:12.967 に答える
2

解決策 1:

my_edittext_bg

 <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >    
    <!-- Color of the border -->
    <stroke
      android:width="2dp"
      android:color="#FF0000" />
    <!-- Use this if you want to round your Corners -->
    <corners android:radius="5dp" />
    <!-- Use this attribute if you want add some paddings -->
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
    </shape>

これを編集テキストの背景として設定します

 android:background="@drawable/my_edittext_bg"

解決策 2:

この 9 パッチ ドローアブルを EditText の背景として使用します

ここに画像の説明を入力

于 2012-07-03T06:29:12.807 に答える
1

このコードを試してください:

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

そして、「textboxes」という名前のドローアブル フォルダーに xml ファイルを作成し、次のコードを記述します。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:color="#f269be"
    android:width="2dp" />
<solid
    android:color="#ffffff" />
</shape>

丸い角の境界から、次のように書きます。

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#009FFFFF"/>
<corners android:radius="10px"/>
<padding android:left="1dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> 
<stroke android:width="2dp" android:color="#AAAAAA" />
</shape>
于 2012-07-03T06:16:23.013 に答える