文件名称:android 通过名字得到资源ID
文件大小:423KB
文件格式:ZIP
更新时间:2017-04-23 10:26:05
demo android 资源id
通过资源名称 获得资源的id package com.example.activitylibrary; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class LibraryActivity extends Activity { String msg = "我是来自Jar中的Activity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(MResource.getIdByName(getApplication(), "layout", "activity_main")); TextView mTextView = (TextView) findViewById(MResource.getIdByName(getApplication(), "id", "textView1")); mTextView.setText(msg); Button mButton = (Button) findViewById(MResource.getIdByName(getApplication(), "id", "button1")); mButton.setText(msg); mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplication(), msg, Toast.LENGTH_SHORT).show(); } }); } }
【文件预览】:
ActivityLibrary
----.project(851B)
----project.properties(563B)
----src()
--------com()
----AndroidManifest.xml(897B)
----res()
--------drawable-ldpi()
--------drawable-hdpi()
--------values-v11()
--------menu()
--------drawable-mdpi()
--------layout()
--------drawable-xhdpi()
--------values()
--------values-v14()
----.settings()
--------org.eclipse.jdt.core.prefs(177B)
--------org.eclipse.core.resources.prefs(58B)
----assets()
----gen()
--------com()
----libs()
--------android-support-v4.jar(377KB)
----.classpath(364B)
----proguard-project.txt(781B)
----ic_launcher-web.png(54KB)
----bin()
--------classes()
--------AndroidManifest.xml(897B)
--------res()