다음을 통해 공유


TypedArray.GetSourceResourceId(Int32, Int32) Method

Definition

Returns the resource ID of the style or layout against which the specified attribute was resolved, otherwise returns defValue.

[Android.Runtime.Register("getSourceResourceId", "(II)I", "GetGetSourceResourceId_IIHandler", ApiSince=29)]
public virtual int GetSourceResourceId (int index, int defaultValue);
[<Android.Runtime.Register("getSourceResourceId", "(II)I", "GetGetSourceResourceId_IIHandler", ApiSince=29)>]
abstract member GetSourceResourceId : int * int -> int
override this.GetSourceResourceId : int * int -> int

Parameters

index
Int32

Index of attribute whose source style to retrieve.

defaultValue
Int32

Value to return if the attribute is not defined or not a resource.

Returns

Either a style resource ID, layout resource ID, or defaultValue if it was not resolved in a style or layout.

Attributes

Remarks

Returns the resource ID of the style or layout against which the specified attribute was resolved, otherwise returns defValue.

For example, if you we resolving two attributes android:attribute1 and android:attribute2 and you were inflating a android.view.View from layout/my_layout.xml:

&lt;View
                    style="@style/viewStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:attribute1="foo"/&gt;

and @style/viewStyle is:

&lt;style android:name="viewStyle"&gt;
                    &lt;item name="android:attribute2"&gt;bar&lt;item/&gt;
                &lt;style/&gt;

then resolved TypedArray will have values that return source resource ID of R.layout.my_layout for android:attribute1 and R.style.viewStyle for android:attribute2.

Java documentation for android.content.res.TypedArray.getSourceResourceId(int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to