Android ids.xml 的作用

ids概述

ids.xml:爲應用的相關資源提供唯一的資源id。id是爲了獲得xml中的對象需要的參數,也就是 Object = findViewById(R.id.id_name); 中的id_name。

使用

例如xml中定義如下

<resources>
    <item type="id" name="btn_next" />
</resources>

xml中使用id

<Button
	android:id="@id/btn_next"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:text="next"/>

java使用id

Button button = new Button(this);
button.setId(R.id.btn_next);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章