新聞中心
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了特克斯免費(fèi)建站歡迎大家使用!
字符串資源
自動(dòng)生成目錄 :Values,生成了三個(gè)
App_name: AndroidManifest.xml使用了
hello_world:activity_main.xml
代碼讀取:
Stringstr=getResources().getString(R.string.app_name);
// System.out.println(str);
tv=(TextView)findViewById(R.id.tv)
tv.setText(R.string.app_name);
2、顏色資源
android:background="#FF0000",可簡化"#F00"
不透明:"#FF00",半透明:"#8F00"
可添加資源:Android xml File類型:value
調(diào)用自己定義:
android:background="@Color/red"
調(diào)用操作系統(tǒng):
android:background="@Android:Color/black"
3、數(shù)組資源
創(chuàng)建Value類型的xml文件:
調(diào)用:
String[] arr=getResources().getStringArray(R.array.arr);
for(String string : arr)
System.out.println(string);
4 Drawable資源
AndroidManifest.xml中:android:icon="@drawable/ic_launcher"
不分分辯率,創(chuàng)建drawable目錄:
拷進(jìn)png文件:20150103122610.png
圖片按鈕,如:
android:id="@+id/p_w_picpathView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/20150103122610" /> 其它按鈕背景: android:background="@drawable/20150103122610" 5 菜單資源 在menu下默認(rèn)生成了菜單項(xiàng):
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.resource6.MainActivity">
android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never"/> 可重寫菜單項(xiàng),菜單的點(diǎn)擊事件如下: @verride publicboolean onOptionsItemSelected(MenuItemitem) { switch(item.getItemId()){ case R.id.action_settings: new AlertDialog.Builder(this).setTitile("標(biāo)題").setMessage("對話框").setPositiveButton("關(guān)閉",null).show(); break; case R.id.action_bar Toast.makeText(this,"消息", Toast_LENTH_SHORT).show(); break; default: break; } }
文章標(biāo)題:10天學(xué)通Android開發(fā)(6)-資源訪問
網(wǎng)站鏈接:http://www.ef60e0e.cn/article/pgggic.html