简体   繁体   English

ANDROID可以在xml数据绑定中声明内置数据类型

[英]ANDROID Can declare Built-In data type in xml data binding

is there a way can declare Built-In data type in xml data binding framework Android? 有没有一种方法可以在Android的xml数据绑定框架中声明内置数据类型?
For example like this: 例如这样:

<data>

<import type="android.text.Html"/>

<variable
  name="isDataFetched"
  type="Boolean"/>
  </data>

thanks. 谢谢。

i use it like this 我这样使用

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable name="backgroundColor"
                  type="Integer"/>
        <variable name="editTextColor"
                  type="Integer"/>
    </data>
<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:backgroundResource="@{backgroundColor!=0?backgroundColor:android.R.color.black}"
    tools:context="ds.gobillsale.FormActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/margin_10"
        android:padding="@dimen/margin_5"
        >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
<TextView
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_horizontal_margin"
    android:text="Date"
    android:textColor="@{editTextColor!=0?context.getResources().getColor(editTextColor):android.R.color.black}"
    android:textSize="18sp"
    android:drawableLeft="@drawable/calander"
    android:drawablePadding="@dimen/margin_10"
    android:id="@+id/ed_date"
    android:background="@drawable/ed_background"/>
            <TextView
                android:layout_width="0dp"
                android:layout_weight=".2"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:textColor="@android:color/holo_blue_bright"
                android:layout_alignParentRight="true"
                />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_20"
                android:orientation="horizontal"
                >

                <EditText
                    android:id="@+id/ed_seller_name"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/ed_background"
                    android:hint="Seller Name"
                    android:drawableLeft="@drawable/seller_name"
                    android:drawablePadding="@dimen/margin_10"
                    android:imeOptions="actionNext"
                    android:inputType="text"
                    android:maxLines="1"
                    android:padding="@dimen/activity_horizontal_margin"
                    android:textColor="@{editTextColor!=0?context.getResources().getColor(editTextColor):android.R.color.black}"
                    android:textColorHint="@color/gray"
                    android:textSize="18sp"
                    />

                <TextView
                    android:layout_width="0dp"
                    android:layout_weight=".2"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="1223"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:layout_alignParentRight="true"
                    android:id="@+id/seller_name_txt_limit"
                    />
            </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_20"
            >
            <EditText
                android:id="@+id/ed_seller_email"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:background="@drawable/ed_background"

                android:drawableLeft="@drawable/seller_email"
                android:drawablePadding="@dimen/margin_10"
                android:hint="Seller Email"
                android:textColorHint="@color/gray"

                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:padding="@dimen/activity_horizontal_margin"
                android:textColor="@{editTextColor!=0?context.getResources().getColor(editTextColor):android.R.color.black}"
                android:textSize="18sp"/>
        <TextView
            android:layout_width="0dp"
            android:layout_weight=".2"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:layout_alignParentRight="true"
            android:id="@+id/seller_email_txt_limit"
            />
    </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_20"
            >
            <EditText
                android:id="@+id/ed_pur_name"
                android:layout_width="0dp"
                android:layout_weight="1"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_horizontal_margin"
    android:hint="Purchaser Name"
    android:inputType="text"
    android:maxLines="1"

    android:imeOptions="actionNext"
                android:textColorHint="@color/gray"

                android:textColor="@{editTextColor!=0?context.getResources().getColor(editTextColor):android.R.color.black}"
    android:textSize="18sp"
    android:drawableLeft="@drawable/seller_name"
    android:drawablePadding="@dimen/margin_10"
                android:background="@drawable/ed_background"
                />
    <TextView
        android:layout_width="0dp"
        android:layout_weight=".2"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="1223"
        android:gravity="center"
        android:textColor="@android:color/white"

        android:layout_alignParentRight="true"
        android:id="@+id/pur_name_txt_limit"
        />
</LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_20"

                >
    <EditText
                android:id="@+id/ed_pur_email"
    android:layout_width="0dp"
                android:layout_weight="1"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_horizontal_margin"
    android:inputType="textEmailAddress"
    android:maxLines="1"
                android:background="@drawable/ed_background"
                android:imeOptions="actionDone"
    android:hint="Purchaser Email"
                android:textColor="@{editTextColor!=0?context.getResources().getColor(editTextColor):android.R.color.black}"
                android:textColorHint="@color/gray"
    android:textSize="18sp"
    android:drawableLeft="@drawable/seller_email"
    android:drawablePadding="@dimen/margin_10"
              />
    <TextView
        android:layout_width="0dp"
        android:layout_weight=".2"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="1223"
        android:gravity="center"

        android:textColor="@android:color/white"

        android:layout_alignParentRight="true"
        android:id="@+id/pur_email_txt_limit"
        />
</LinearLayout>

    </LinearLayout>
    </ScrollView>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img_next"
    android:layout_centerInParent="true"
    android:layout_alignParentBottom="true"

    android:src="@drawable/next_arrow"/>
        <ImageView
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"

    android:src="@drawable/watermark_logo"/>

    </RelativeLayout>

</LinearLayout>
</layout>

and programmatically access it in my onCreate method 并在我的onCreate方法中以编程方式访问它

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

 ActivityFormBinding binding=  DataBindingUtil.setContentView(this,R.layout.activity_form);
   binding.setEditTextColor(R.color.green);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM