Tae*_*hin 21 resources android
让我们假设我在我的应用程序中的res布局中有这个
<TextView android:id="@+id/titleText" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/app_name"
android:textColor="#ffffffb0" android:padding="5px" />
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我使用此命令获取TextView
TextView tv = (TextView)findViewById(R.id.titleText);
Run Code Online (Sandbox Code Playgroud)
但我正在寻找另一种这样的方法
TextView tv = (TextView)findViewByString("R.id."+"titleText");
Run Code Online (Sandbox Code Playgroud)
因为我需要列举那些ID.你们中的任何一个人都可以给出一个暗示或线索,我该如何解决这个问题?谢谢
Ted*_*opp 50
你可以使用这样的东西:
Resources res = getResources();
int id = res.getIdentifier("titleText", "id", getContext().getPackageName());
Run Code Online (Sandbox Code Playgroud)
然后使用id.
| 归档时间: |
|
| 查看次数: |
15969 次 |
| 最近记录: |