日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 中resources管理

發布時間:2025/3/17 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 中resources管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

主要存在于res/value文件夾中

定義:

dimen.xml:主要用于設置像素默認值

<resources>

?res/values/dimens.xml

<dimen name="sp_12">12sp</dimen>
<dimen name="sp_13">13sp</dimen>

?<dimen name="dip_40">40dip</dimen>
?<dimen name="dip_45">45dip</dimen>

</resources>

代碼使用:

int width=getContext().getResources().getDimension(R.dimen.tab_width);

xml文件使用:

android:layout_width="@dimen/tab_width"

color.xml設置顏色

<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="drawable" name="main_background">#FFE7E7E7</item>
<item type="drawable" name="newslist_item_background">#FFE7E7E7</item>
<item type="color" name="white">#FFFFFFFF</item>
<item type="color" name="category_title_normal_background">#FFADB2AD</item>
<item type="color" name="gold">#b89766</item>
<item type="color" name="transparent">#000000</item>
<item type="color" name="textcolor">#FFFFFF</item>
<item type="color" name="bgcolor">#000000</item>
</resources>

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="contents_text">#ff000000</color>
<color name="encode_view">#ffffffff</color>
<color name="possible_result_points">#c0ffff00</color>
<color name="result_points">#c000ff00</color>
<color name="result_text">#ffffffff</color>
<color name="result_view">#b0000000</color>
<color name="share_text">#ff000000</color>
<color name="status_view">#50000000</color>
<color name="status_text">#ffffffff</color>
<color name="transparent">#00000000</color>
<color name="viewfinder_frame">#ff000000</color>
<color name="viewfinder_laser">#ffff0000</color>
<color name="viewfinder_mask">#60000000</color>
<color name="red">#ffff0000</color>
<color name="blue">#ff3590c4</color>
<color name="green">#7700ff00</color>
<color name="yellow">#ffff7000</color>
<color name="screen_background_white">#00ffffff</color>
<color name="translucent_background">#00000000</color>
<color name="white_background">#00ffffff</color>
<color name="gray_background">#fff7f7f7</color>
<color name="solid_red">#ffff0000</color>
<color name="solid_while">#ff888888</color>
<color name="solid_saffron">#ffff6414</color>
<color name="solid_blue">#ff0000ff</color>
<color name="solid_green">#ff00ff00</color>
<color name="solid_yellow">#ffffff00</color>
<color name="saffron">#ffffa649</color>
<color name="titlebackgroundcolor">#fffe8625</color>
<color name="listitem_divide">#ffd4d3d3</color>
<color name="gray">#ff666664</color>
<color name="deep_gray">#ff555555</color>
<color name="light_gray">#ff757575</color>
<color name="btn_focused_color_yellow">#fffdfdfd</color>
<color name="btn_pressed_color_light">#fffdfdfd</color>
<color name="btn_default_color_light">#ffff5f11</color>
<color name="rounded_container_border">#ffb7babb</color>
<color name="base_start_color_default">#ffffffff</color>
<color name="base_end_color_default">#ffffffff</color>
<color name="base_start_color_pressed">#ffff7a13</color>
<color name="base_center_color_pressed">#ffff8c2f</color>
<color name="base_end_color_pressed">#ffffa254</color>
<color name="text_color_default">#ff000000</color>
<color name="text_color_pressed">#ffffffff</color>
</resources>

調用color標簽:android:background="@color/red"?@color/是調用res/下的匹配的color標簽?

也可以將color標簽嵌入到selector的item標簽中使用 ?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="@color/red"/>
<item android:color="@color/green" />
</selector>

?

代碼設置color方法:

testview.setTextColor(Color.parseColor("FFFFFF"));?

testview.setTextColor(Color.GRAY);

tv.setTextColor(Color.rgb(255,?255,?255));?

testview.setTextColor(getContext().getResources().getColor(R.color.my_color));

?

?

array.xml

<resources>
????<declare-styleable name="DragSort">
??????? <attr name="collapsed_height" format="dimension" />
??????? <attr name="drag_scroll_start" format="float" />
??????? <attr name="max_drag_scroll_speed" format="float" />
??????? <attr name="float_background_color" format="color" />
??????? <attr name="remove_mode">
??????????? <enum name="clickRemove" value="0" />
??????????? <enum name="flingRemove" value="1" />
??????? </attr>
??????? <attr name="track_drag_sort" format="boolean" />
??????? <attr name="float_alpha" format="float" />
??????? <attr name="slide_shuffle_speed" format="float" />
??????? <attr name="remove_animation_duration" format="integer" />
??????? <attr name="drop_animation_duration" format="integer" />
??????? <attr name="drag_enabled" format="boolean" />
??????? <attr name="sort_enabled" format="boolean" />
??????? <attr name="remove_enabled" format="boolean" />
??????? <attr name="drag_start_mode">
??????????? <enum name="onDown" value="0" />
??????????? <enum name="onMove" value="1" />
??????????? <enum name="onLongPress" value="2" />
??????? </attr>
??????? <attr name="drag_handle_id" format="integer" />
??????? <attr name="fling_handle_id" format="integer" />
??????? <attr name="click_remove_id" format="integer" />
??????? <attr name="use_default_controller" format="boolean" />
??? </declare-styleable>

</resources>

代碼使用:

?TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.DragSort, 0, 0);

?????????mItemHeight = Math.max(1, array.getDimensionPixelSize(R.styleable.DragSortListView_collapsed_height, 1));

?????????mTrackDragSort = array.getBoolean( R.styleable.DragSortListView_track_drag_sort, false);

xml使用:

??? <ListPreference
??? ?android:title="@string/page_animation"
??? ?android:defaultValue="@string/default_page_animation"
??? ?android:entries="@array/page_animation_labels"
??? ?android:entryValues="@array/page_animations"
??? ?android:key="pageAnimation"
??? ?/>

?

strings.xml:主要設置文本

<resources>

?<string name="button_confirm">確定</string>?????
?<string name="button_cancel">取消</string>???

?<string-array name="page_animations">
??<item>100</item>
??<item>0</item>
??<item>1</item>
??<item>2</item>
??<item>3</item>
?</string-array>

</resources>

代碼使用:

testview.setText(getString(R.string.button_confirm));

xml使用:

android:text="@string/button_confirm"

?

風格style與主題theme區別:

1:style主要用于View,theme主要用于Activity以及Application

2、style主要用于設置View的屬性,theme主要用設置Activity的樣式如是:否全屏

3、style與theme都是以<style><item>文本</item></style>創建,只是item的內容不一樣

style定義:

style.xml文件

<resources xmlns:android="http://schemas.android.com/apk/res/android">

?<style name="TitleStyle">?

  <item name="android:textSize">18sp</item>

  <item name="android:textColor">#ec9237</item>

</style>

<style name="Title" parent="@style/TitleStyle">?(繼承TitleStyle屬性)

  <item name="android:textSize">5sp</item>?

</style>?

?</resources>

代碼使用:

?

xml使用:

<EditText android:layout_height="wrap_content"

android:text="EditText"

style="@style/Title"?

android:layout_width="fill_parent"?

android:id="@+id/editText1" />

-----------------------------------------------

theme:

style.xml

1.<?xml version="1.0" encoding="utf-8"?>

<resources>

  <style name="theme1">

    <item name="android:windowNoTitle">true</item>?

    <item name="android:windowFullscreen">?android:windowNoTitle</item>?

  </style>?

  <style name="theme2.a">

    <item name="android:windowNoTitle">true</item>?

    <item name="android:windowFullscreen">?android:windowNoTitle</item>?

  </style>?

</resources>?

代碼使用:

注意:setTheme應該在setContentView之前調用。

setTeme(R.theme.theme1);/setTeme(R.style.theme1)

setContentView(R.layout.main);

?

xml使用主題:

<application

  android:icon="@drawable/icon" android:label="@string/app_name"?

  android:theme="@style/theme1">

  <activity

    android:name=".MessageShowActivity" android:label="@string/app_name"?

    android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait"

    android:theme="@style/theme2">

  </activity>

</application>?

---------------------------------

android的selector是在drawable/xxx.xml中創建的:

selector:主要用設置view點擊選中顯示效果

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
  android:color="hex_color"
  android:state_pressed=["true" | "false"]
  android:state_focused=["true" | "false"]
  android:state_selected=["true" | "false"]
  android:state_checkable=["true" | "false"]
  android:state_checked=["true" | "false"]
  android:state_enabled=["true" | "false"]
  android:state_window_focused=["true" | "false"] />
</selector>

android:drawable 放一個drawable資源
android:state_pressed 是否按下,如一個按鈕觸摸或者點擊。
android:state_focused 是否取得焦點,比如用戶選擇了一個文本框。
android:state_hovered 光標是否懸停,通常與focused state相同,它是4.0的新特性
android:state_selected 被選中,它與focus state并不完全一樣,如一個list view 被選中的時候,它里面的各個子組件可能通過方向鍵,被選中了。
android:state_checkable 組件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一個RadioButton可以被check了。
android:state_enabled 能夠接受觸摸或者點擊事件
android:state_activated 被激活(這個麻煩舉個例子,不是特明白)
android:state_window_focused 應用程序是否在前臺,當有通知欄被拉下來或者一個對話框彈出的時候應用程序就不在前臺了
-------

<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_window_focused="false" android:drawable="@drawable/pic1" /><!-- 沒有焦點時的背景圖片-->
  <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/pic2" /><!-- 非觸摸模式下獲得焦點并單擊時的背景圖片-->
  <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pic3" /><!-- 觸摸模式下單擊時的背景圖片-->
  <item android:state_selected="true" android:drawable="@drawable/pic4" /><!--選中時的圖片背景-->
  <item android:state_focused="true" android:drawable="@drawable/pic5" /><!--獲得焦點時的圖片背景-->
 </selector>

?

在xml中使用示例:

res/color/button_text.xml

<?xml version="1.0" encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
? ? ? ? android:color="#ffff0000"/><!-- pressed -->
? ?<item
android:state_focused
="true"
? ? ? ? android:color="#ff0000ff"/><!-- focused -->
? ?<itemandroid:color="#ff000000"/><!-- default -->
</selector> <Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text"/>

參考:http://www.cnblogs.com/navy-wang/p/3314034.html

本文轉自歡醉博客園博客,原文鏈接http://www.cnblogs.com/zhangs1986/p/3624482.html如需轉載請自行聯系原作者


歡醉

總結

以上是生活随笔為你收集整理的android 中resources管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲美女自拍偷拍 | 日韩久久久久久久久 | 国产丝袜视频在线观看 | 天天干夜夜怕 | 少妇视频网 | 手机成人av| 影音先锋美女 | 久草a视频 | 亚洲精品国产精品国自产观看浪潮 | 国产h片在线观看 | 免费高清视频一区二区三区 | 脱美女衣服亲摸揉视频 | 丁香六月婷婷综合 | 麻豆av免费在线观看 | 亚洲av色一区二区三区精品 | 国产又粗又黄又爽的视频 | www.亚洲欧美 | 日韩av片免费观看 | 91麻豆一区二区三区 | 黄色大片网站在线观看 | 亚洲伊人天堂 | 简单av网| www.久色| 欧美日韩大片在线观看 | 午夜免费视频网站 | 综合久久精品 | 久久爱网| 超碰超碰超碰超碰 | 亚洲一区二区福利 | 亚洲不卡在线观看 | 久久久久在线 | 免费看黄色网 | 成年人在线免费观看 | 香蕉视频在线网站 | 黄色av网址大全 | 午夜视频福利在线观看 | 婷婷伊人久久 | 妺妺窝人体色777777 | 国产黄色免费视频 | 麻豆网站在线播放 | 少妇4p | 91超薄丝袜肉丝一区二区 | 六月婷婷色 | 国产av电影一区二区 | 麻豆网站在线免费观看 | 亚洲女人天堂网 | 久热中文 | 黑巨茎大战欧美白妞 | 日韩美女性生活 | 天天色天| 成人区人妻精品一熟女 | 无码精品国产一区二区三区 | 日日燥夜夜燥 | 日韩欧美卡一卡二 | 午夜精品福利在线观看 | 黄色精彩视频 | 91久久久久国产一区二区 | 一区二区三区美女视频 | 写真福利片hd在线播放 | 亚洲成人免费看 | 一区二区三区视频免费在线观看 | 日韩三级观看 | 男人天堂999 | 放几个免费的毛片出来看 | 国产人成| 18成人在线 | 天天操天天爽天天射 | 欧美成人专区 | 熟妇人妻无码xxx视频 | 无码人妻丰满熟妇区bbbbxxxx | 91资源在线播放 | 久操社区 | 一区二区三区四区视频在线观看 | 91麻豆产精品久久久久久夏晴子 | 91麻豆视频在线观看 | 亚洲免费一区二区 | 久久三区| 国产成人一区二区三区 | 国产美女久久久 | 99这里| 中文字幕a级片 | 美女黄色片网站 | 久久人人爽爽人人爽人人片av | 色偷偷视频 | 99热这里只有精品7 青青草社区 | 日韩aaa | 97国产精品久久久 | 巨物撞击尤物少妇呻吟 | 亚洲一区二区三区四区在线观看 | 久久无吗视频 | 香蕉爱爱视频 | 久久性视频 | 午夜av免费在线观看 | 中文在线8资源库 | 一区二区免费在线视频 | 色综合99| 黑人极品videos精品欧美裸 | 国产一区免费看 | 狠狠撸狠狠干 |