をお試しください:
EX:
var applicationNameId = Resources.GetIdentifier("ApplicationName", "string", this.PackageName);
これはなるだろうstrings.xml
ファイルのApplicationName
アイテムのリソースID。言い換えれば
<string name="ApplicationName">AppName</string>
、私はこれが私を与え、同じint
のための私のResource.Designer.cs
を検索識別子を取ることができるはずです。
ビュー+id/
名前の識別子を取得したい場合は、代わりに次のない場合があります
EX:Button
のリソースIDを取得します
var buttonNameId = Resources.GetIdentifier("MyButton", "id", this.PackageName);
Id:MyButton
:
<Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Hello"
/>
しかし、ドキュメントに基づいて、名前ではなくIDでリソースを取得するよりもはるかに遅いので、これはお勧めしません。
注:この機能の使用はお勧めしません。名前よりも識別子でリソースを取得する方がはるかに効率的です。
https://developer.android.com/reference/android/content/res/Resources.html#getIdentifier(java.lang.String, java.lang.String, java.lang.String)
'getResources()。getIdentifier'は正しいアプローチです。それをどうやって行うのかを示し、それを修正しようとします。 –