ホームページ  >  記事  >  バックエンド開発  >  XML リソース ファイルを使用して色やスタイルなどを定義する方法の詳細な紹介。

XML リソース ファイルを使用して色やスタイルなどを定義する方法の詳細な紹介。

黄舟
黄舟オリジナル
2017-03-08 16:51:112900ブラウズ

1. XML リソース ファイルを使用して色を定義します。この方法は拡張性に優れており、たとえば、色の値を取得するために mycolor を作成します。 XML リソース ファイルを使用してスタイルを定義し、res/drawable でshape.xml ファイルを定義します

サンプル コード:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="mycolor">#ffb52121</color> 
</resources>

アクティビティ内ボタン

Android:textColor="@drawable/mycolor"

Shape の属性は、XML で定義されます (activity_main など)。

プロパティ:

<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android" >  
  
    <corners android:radius="5dp" />  
  
    <size  
        android:height="30dp"  
        android:width="20dp" />  
  
    <gradient   
        android:startColor="#9933cc"  
        android:endColor="#aa66cc"  
        android:angle="90"  
        />  
      
    <padding android:left="5dp"  
        android:right="5dp"  
        android:top="5dp"  
        android:bottom="5dp"/>  
  
</shape>  
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
 
    <!-- 填充的颜色:这里设置背景透明 -->
    <solid android:color="@android:color/transparent" />
    <!-- 边框的颜色 :不能和窗口背景色一样-->
    <stroke
        android:width="3dp"
        android:color="#ffffff" />
    <!-- 设置按钮的四个角为弧形 -->
    <!-- android:radius 弧形的半径 -->
    <corners android:radius="5dip" />
 
    <!-- padding:Button里面的文字与Button边界的间隔 -->
    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />
</shape>

gradient

グラデーションカラー

グラデーションカラー

説明: パディング

属性:

<Button
    android:id="@+id/roundButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/shape"
    android:text=" 圆角按钮 " />

以上がXML リソース ファイルを使用して色やスタイルなどを定義する方法の詳細な紹介。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。