রিসোর্স হলো আপনার কোডে ব্যবহৃত অতিরিক্ত ফাইল এবং স্ট্যাটিক কন্টেন্ট, যেমন বিটম্যাপ, লেআউট সংজ্ঞা, ইউজার ইন্টারফেস স্ট্রিং, অ্যানিমেশন নির্দেশাবলী এবং আরও অনেক কিছু।
আপনার কোড থেকে ছবি এবং স্ট্রিং এর মতো অ্যাপ রিসোর্সগুলিকে সর্বদা এক্সটারনালাইজ করুন, যাতে আপনি সেগুলিকে স্বাধীনভাবে রক্ষণাবেক্ষণ করতে পারেন। এছাড়াও, নির্দিষ্ট ডিভাইস কনফিগারেশনের জন্য বিকল্প রিসোর্সগুলি বিশেষভাবে নামযুক্ত রিসোর্স ডিরেক্টরিতে গ্রুপ করে প্রদান করুন। রানটাইমে, অ্যান্ড্রয়েড বর্তমান কনফিগারেশনের উপর ভিত্তি করে উপযুক্ত রিসোর্স ব্যবহার করে। উদাহরণস্বরূপ, আপনি স্ক্রিনের আকারের উপর নির্ভর করে একটি ভিন্ন UI লেআউট অথবা ভাষা সেটিং এর উপর নির্ভর করে ভিন্ন স্ট্রিং প্রদান করতে চাইতে পারেন।
একবার আপনি আপনার অ্যাপ রিসোর্সগুলিকে এক্সটার্নালাইজ করার পর, আপনার প্রোজেক্টের R ক্লাসে তৈরি রিসোর্স আইডি ব্যবহার করে আপনি সেগুলি অ্যাক্সেস করতে পারবেন। এই ডকুমেন্টটি আপনাকে দেখায় যে কীভাবে আপনার অ্যান্ড্রয়েড প্রোজেক্টে রিসোর্সগুলিকে গ্রুপ করতে হয়। এটি আপনাকে দেখায় যে কীভাবে নির্দিষ্ট ডিভাইস কনফিগারেশনের জন্য বিকল্প রিসোর্স সরবরাহ করতে হয় এবং তারপরে আপনার অ্যাপ কোড বা অন্যান্য XML ফাইল থেকে সেগুলি অ্যাক্সেস করতে হয়।
গ্রুপ রিসোর্সের ধরণ
আপনার প্রকল্পের res/ ডিরেক্টরির একটি নির্দিষ্ট সাবডিরেক্টরিতে প্রতিটি ধরণের রিসোর্স রাখুন। উদাহরণস্বরূপ, একটি সাধারণ প্রকল্পের জন্য ফাইলের শ্রেণিবিন্যাস এখানে দেওয়া হল:
MyProject/
src/
MyActivity.java
res/
drawable/
graphic.png
layout/
main.xml
info.xml
mipmap/
icon.png
values/
strings.xml
res/ ডিরেক্টরিতে তার সাবডিরেক্টরিতে থাকা সমস্ত রিসোর্স থাকে: একটি ইমেজ রিসোর্স, দুটি লেআউট রিসোর্স, লঞ্চার আইকনের জন্য একটি mipmap/ ডিরেক্টরি এবং একটি স্ট্রিং রিসোর্স ফাইল। রিসোর্স ডিরেক্টরির নামগুলি গুরুত্বপূর্ণ এবং সারণি 1 এ বর্ণনা করা হয়েছে।
দ্রষ্টব্য: mipmap ফোল্ডার ব্যবহার সম্পর্কে আরও তথ্যের জন্য, mipmap ডিরেক্টরিতে অ্যাপ আইকন রাখুন দেখুন।
সারণি ১. প্রকল্পের res/ ডিরেক্টরির ভিতরে সমর্থিত রিসোর্স ডিরেক্টরি।
| ডিরেক্টরি | রিসোর্সের ধরণ |
|---|---|
animator/ | XML ফাইল যা সম্পত্তি অ্যানিমেশন সংজ্ঞায়িত করে। |
anim/ | XML ফাইল যা Tween অ্যানিমেশন সংজ্ঞায়িত করে। এই ডিরেক্টরিতে প্রপার্টি অ্যানিমেশনগুলিও সংরক্ষণ করা যেতে পারে, তবে দুটি ধরণের মধ্যে পার্থক্য করার জন্য প্রপার্টি অ্যানিমেশনের জন্য animator/ ডিরেক্টরি পছন্দ করা হয়। |
color/ | XML ফাইল যা রঙের একটি স্টেট তালিকা সংজ্ঞায়িত করে। আরও তথ্যের জন্য, রঙের স্টেট তালিকার রিসোর্স দেখুন। |
drawable/ | বিটম্যাপ ফাইল (PNG,
আরও তথ্যের জন্য, অঙ্কনযোগ্য সম্পদ দেখুন। |
mipmap/ | বিভিন্ন লঞ্চার আইকন ঘনত্বের জন্য অঙ্কনযোগ্য ফাইল। mipmap/ ফোল্ডার দিয়ে লঞ্চার আইকন পরিচালনা সম্পর্কে আরও তথ্যের জন্য, mipmap ডিরেক্টরিতে অ্যাপ আইকন রাখুন দেখুন। |
layout/ | XML ফাইল যা একটি ইউজার ইন্টারফেস লেআউট সংজ্ঞায়িত করে। আরও তথ্যের জন্য, লেআউট রিসোর্স দেখুন। |
menu/ | XML ফাইল যা অ্যাপ মেনু সংজ্ঞায়িত করে, যেমন একটি অপশন মেনু, প্রসঙ্গ মেনু, অথবা সাবমেনু। আরও তথ্যের জন্য, মেনু রিসোর্স দেখুন। |
raw/ | অবাধ ফাইলগুলিকে তাদের raw আকারে সংরক্ষণ করতে হবে। raw তবে, যদি আপনার মূল ফাইলের নাম এবং ফাইলের শ্রেণিবিন্যাসে অ্যাক্সেসের প্রয়োজন হয়, |
values/ | XML ফাইলগুলিতে স্ট্রিং, পূর্ণসংখ্যা এবং রঙের মতো সহজ মান থাকে। অন্যান্য যেহেতু প্রতিটি রিসোর্স তার নিজস্ব XML উপাদান দিয়ে সংজ্ঞায়িত করা হয়েছে, আপনি আপনার পছন্দের ফাইলটির নামকরণ করতে পারেন এবং একটি ফাইলে বিভিন্ন রিসোর্স টাইপ রাখতে পারেন। তবে, স্পষ্টতার জন্য, আপনি বিভিন্ন ফাইলে অনন্য রিসোর্স টাইপ রাখতে চাইতে পারেন। উদাহরণস্বরূপ, এই ডিরেক্টরিতে আপনি যে রিসোর্স তৈরি করতে পারেন তার জন্য এখানে কিছু ফাইলের নাম নিয়মাবলী দেওয়া হল:
আরও তথ্যের জন্য, স্ট্রিং রিসোর্স , স্টাইল রিসোর্স এবং আরও রিসোর্সের ধরণ দেখুন। |
xml/ | রানটাইমে Resources.getXML() কল করে যে সকল অনিয়মিত XML ফাইল পড়া যায়। বিভিন্ন XML কনফিগারেশন ফাইল এখানে সংরক্ষণ করতে হবে, যেমন Search কনফিগারেশন । |
font/ | TTF, OTF, অথবা TTC এর মতো এক্সটেনশন সহ ফন্ট ফাইল, অথবা XML ফাইল যাতে একটি <font-family> উপাদান থাকে। ফন্টগুলি সম্পদ হিসেবে সম্পর্কে আরও তথ্যের জন্য, XML সম্পদ হিসেবে একটি ফন্ট যোগ করুন দেখুন। |
সাবধানতা: কখনোই সরাসরি res/ ডিরেক্টরির ভেতরে রিসোর্স ফাইল সংরক্ষণ করবেন না। এটি একটি কম্পাইলার ত্রুটির কারণ হয়।
পৃথক ধরণের সম্পদ সম্পর্কে আরও তথ্যের জন্য, সম্পদের প্রকারের সারসংক্ষেপ দেখুন।
সারণি ১-এ সংজ্ঞায়িত সাবডিরেক্টরিতে আপনি যে রিসোর্সগুলি সংরক্ষণ করেন সেগুলি হল আপনার ডিফল্ট রিসোর্স। অর্থাৎ, এই রিসোর্সগুলি আপনার অ্যাপের জন্য ডিফল্ট ডিজাইন এবং কন্টেন্ট সংজ্ঞায়িত করে। তবে, বিভিন্ন ধরণের অ্যান্ড্রয়েড-চালিত ডিভাইসের জন্য বিভিন্ন ধরণের রিসোর্সের প্রয়োজন হতে পারে।
উদাহরণস্বরূপ, অতিরিক্ত স্ক্রিন স্পেসের সুবিধা নেওয়ার জন্য আপনি সাধারণ স্ক্রিনের চেয়ে বড় ডিভাইসগুলির জন্য বিভিন্ন লেআউট রিসোর্স সরবরাহ করতে পারেন। আপনি ডিভাইসের ভাষা সেটিংসের উপর ভিত্তি করে আপনার ব্যবহারকারী ইন্টারফেসে পাঠ্য অনুবাদ করে এমন বিভিন্ন স্ট্রিং রিসোর্সও সরবরাহ করতে পারেন। বিভিন্ন ডিভাইস কনফিগারেশনের জন্য এই বিভিন্ন রিসোর্স সরবরাহ করতে, আপনার ডিফল্ট রিসোর্স ছাড়াও বিকল্প রিসোর্স সরবরাহ করতে হবে।
বিকল্প সম্পদ প্রদান করুন
বেশিরভাগ অ্যাপ নির্দিষ্ট ডিভাইস কনফিগারেশন সমর্থন করার জন্য বিকল্প রিসোর্স প্রদান করে। উদাহরণস্বরূপ, বিভিন্ন স্ক্রিন ঘনত্বের জন্য বিকল্প ড্রয়েবল রিসোর্স এবং বিভিন্ন ভাষার জন্য বিকল্প স্ট্রিং রিসোর্স অন্তর্ভুক্ত করুন। রানটাইমে, অ্যান্ড্রয়েড বর্তমান ডিভাইস কনফিগারেশন সনাক্ত করে এবং আপনার অ্যাপের জন্য উপযুক্ত রিসোর্স লোড করে।

চিত্র ১. স্ক্রিনের আকারের উপর ভিত্তি করে দুটি ডিভাইস ভিন্ন লেআউট রিসোর্স ব্যবহার করছে।
রিসোর্সের একটি সেটের জন্য কনফিগারেশন-নির্দিষ্ট বিকল্পগুলি নির্দিষ্ট করতে, নিম্নলিখিতগুলি করুন:
-
<resources_name> - <qualifier>ফর্মেres/নামে একটি নতুন ডিরেক্টরি তৈরি করুন।-
<resources_name>হল সংশ্লিষ্ট ডিফল্ট রিসোর্সের ডিরেক্টরি নাম (টেবিল ১ এ সংজ্ঞায়িত)। -
<qualifier>হল এমন একটি নাম যা একটি পৃথক কনফিগারেশন নির্দিষ্ট করে যার জন্য এই সংস্থানগুলি ব্যবহার করা হবে (সারণী 2 তে সংজ্ঞায়িত)।
আপনি একাধিক
<qualifier>যোগ করতে পারেন। প্রতিটিকে ড্যাশ দিয়ে আলাদা করুন।সতর্কতা: একাধিক যোগ্যতা যোগ করার সময়, আপনাকে অবশ্যই টেবিল ২-এ তালিকাভুক্ত ক্রমে সেগুলিকে একই ক্রমে রাখতে হবে। যদি যোগ্যতা ভুলভাবে ক্রমানুসারে সাজানো হয়, তাহলে সম্পদগুলি উপেক্ষা করা হবে।
-
- এই নতুন ডিরেক্টরিতে উপযুক্ত বিকল্প রিসোর্সগুলি সংরক্ষণ করুন। রিসোর্স ফাইলগুলির নাম অবশ্যই ডিফল্ট রিসোর্স ফাইলগুলির মতোই রাখতে হবে।
উদাহরণস্বরূপ, এখানে কিছু ডিফল্ট এবং বিকল্প সম্পদ রয়েছে:
res/
drawable/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
hdpi কোয়ালিফায়ার ইঙ্গিত দেয় যে সেই ডিরেক্টরিতে থাকা রিসোর্সগুলি উচ্চ-ঘনত্বের স্ক্রিনযুক্ত ডিভাইসগুলির জন্য। এই অঙ্কনযোগ্য ডিরেক্টরিগুলিতে থাকা ছবিগুলি নির্দিষ্ট স্ক্রিন ঘনত্বের জন্য আকারযুক্ত, তবে ফাইলের নামগুলি হুবহু একই। এইভাবে, icon.png বা background.png চিত্রটি উল্লেখ করার জন্য আপনি যে রিসোর্স আইডি ব্যবহার করেন তা সর্বদা একই থাকে। অ্যান্ড্রয়েড রিসোর্স ডিরেক্টরি নামের কোয়ালিফায়ারগুলির সাথে ডিভাইস কনফিগারেশন তথ্যের তুলনা করে বর্তমান ডিভাইসের সাথে সবচেয়ে ভাল মেলে এমন প্রতিটি রিসোর্সের সংস্করণ নির্বাচন করে।
সতর্কতা: বিকল্প রিসোর্স সংজ্ঞায়িত করার সময়, নিশ্চিত করুন যে আপনি রিসোর্সটি একটি ডিফল্ট কনফিগারেশনেও সংজ্ঞায়িত করেছেন। অন্যথায়, ডিভাইসটি কনফিগারেশন পরিবর্তন করলে আপনার অ্যাপ রানটাইম ব্যতিক্রমের সম্মুখীন হতে পারে। উদাহরণস্বরূপ, যদি আপনি values-en তে একটি স্ট্রিং যোগ করেন এবং values না যোগ করেন, তাহলে ব্যবহারকারী যখন ডিফল্ট সিস্টেম ভাষা পরিবর্তন করেন তখন আপনার অ্যাপটি একটি Resource Not Found ব্যতিক্রমের সম্মুখীন হতে পারে।
সারণি ২-এ অগ্রাধিকারের ক্রম অনুসারে বৈধ কনফিগারেশন কোয়ালিফায়ারগুলি তালিকাভুক্ত করা হয়েছে। আপনি প্রতিটি কোয়ালিফায়ারকে একটি ড্যাশ দিয়ে আলাদা করে একটি ডিরেক্টরি নামে একাধিক কোয়ালিফায়ার যোগ করতে পারেন। যদি আপনি একটি রিসোর্স ডিরেক্টরির জন্য একাধিক কোয়ালিফায়ার ব্যবহার করেন, তাহলে আপনাকে অবশ্যই টেবিলে তালিকাভুক্ত ক্রম অনুসারে ডিরেক্টরি নামের সাথে সেগুলি যোগ করতে হবে।
সারণী 2। কনফিগারেশন কোয়ালিফায়ার নাম।
| কনফিগারেশন | যোগ্যতার মান | বিবরণ |
|---|---|---|
| এমসিসি এবং এমএনসি | উদাহরণ:mcc310mcc208-mnc00 | মোবাইল কান্ট্রি কোড (MCC), ঐচ্ছিকভাবে ডিভাইসের সিম কার্ড থেকে মোবাইল নেটওয়ার্ক কোড (MNC) অনুসরণ করে। উদাহরণস্বরূপ, যেকোনো ক্যারিয়ারে যদি ডিভাইসটি একটি রেডিও সংযোগ ব্যবহার করে (অর্থাৎ, এটি একটি GSM ফোন), তাহলে MCC এবং MNC মানগুলি সিম কার্ড থেকে আসে। উদাহরণস্বরূপ, আপনি আপনার অ্যাপে দেশ-নির্দিষ্ট আইনি সংস্থান অন্তর্ভুক্ত করার জন্য শুধুমাত্র MCC ব্যবহার করতে পারেন। যদি আপনাকে শুধুমাত্র ভাষার উপর ভিত্তি করে নির্দিষ্ট করতে হয়, তাহলে ভাষা, স্ক্রিপ্ট (ঐচ্ছিক) এবং অঞ্চল (ঐচ্ছিক) যোগ্যতা ব্যবহার করুন। যদি আপনি MCC এবং MNC যোগ্যতা ব্যবহার করেন, তাহলে সাবধানতার সাথে তা করুন এবং পরীক্ষা করুন যে এটি প্রত্যাশা অনুযায়ী কাজ করে। এছাড়াও কনফিগারেশন ক্ষেত্রগুলি দেখুন |
| ভাষা, লিপি (ঐচ্ছিক), এবং অঞ্চল (ঐচ্ছিক) | উদাহরণ:enfren-rUSfr-rFRfr-rCAb+enb+en+USb+es+419b+zh+Hantb+sr+Latn+RS | ভাষাটি একটি দুই-অক্ষরের ISO 639-1 ভাষা কোড দ্বারা সংজ্ঞায়িত করা হয়, ঐচ্ছিকভাবে একটি দুই-অক্ষরের ISO 3166-1-alpha-2 অঞ্চল কোড (ছোট হাতের কোডগুলি কেস-সংবেদনশীল নয় । অঞ্চলের অংশকে আলাদা করার জন্য অ্যান্ড্রয়েড ৭.০ (এপিআই লেভেল ২৪) BCP ৪৭ ভাষা ট্যাগের জন্য সমর্থন চালু করেছে, যা আপনি ভাষা- এবং অঞ্চল-নির্দিষ্ট রিসোর্সগুলিকে যোগ্যতা অর্জনের জন্য ব্যবহার করতে পারেন। একটি ভাষা ট্যাগ এক বা একাধিক সাবট্যাগের ক্রম থেকে তৈরি করা হয়, যার প্রতিটি সামগ্রিক ট্যাগ দ্বারা চিহ্নিত ভাষার পরিসরকে পরিমার্জিত বা সংকুচিত করে। ভাষা ট্যাগ সম্পর্কে আরও তথ্যের জন্য, ভাষা সনাক্তকরণের জন্য ট্যাগগুলি দেখুন। একটি BCP 47 ভাষা ট্যাগ ব্যবহার করতে, ব্যবহারকারীরা সিস্টেম সেটিংসে ভাষা পরিবর্তন করলে আপনার অ্যাপের জীবনকাল জুড়ে ভাষা ট্যাগ পরিবর্তন হতে পারে। রানটাইম চলাকালীন এটি আপনার অ্যাপকে কীভাবে প্রভাবিত করতে পারে সে সম্পর্কে তথ্যের জন্য, হ্যান্ডেল কনফিগারেশন পরিবর্তনগুলি দেখুন। অন্যান্য ভাষার জন্য আপনার অ্যাপ স্থানীয়করণের সম্পূর্ণ নির্দেশিকা জানতে, আপনার অ্যাপ স্থানীয়করণ দেখুন। এছাড়াও |
| ব্যাকরণগত লিঙ্গ | masculinefeminineneuter | ব্যবহারকারীর ব্যাকরণগত লিঙ্গ। ব্যাকরণগত লিঙ্গ আছে এমন ভাষাগুলির জন্য ব্যবহৃত। উদাহরণস্বরূপ, যদি আপনার ফরাসি ভাষাভাষী ব্যবহারকারীদের জন্য বিভিন্ন সংস্থান সরবরাহ করার প্রয়োজন হয়, তাহলে আপনি নিম্নলিখিত ডিরেক্টরিগুলি ব্যবহার করতে পারেন: দেখুন: অ্যান্ড্রয়েডে ব্যাকরণগত প্রতিফলন । এছাড়াও API লেভেল 34-এ যোগ করা হয়েছে। |
| লেআউটের দিকনির্দেশনা | ldrtlldltr | আপনার অ্যাপের লেআউট দিকনির্দেশনা। এটি যেকোনো রিসোর্সের ক্ষেত্রে প্রযোজ্য হতে পারে, যেমন লেআউট, ড্রয়েবল, অথবা মান। উদাহরণস্বরূপ, যদি আপনি আরবি ভাষার জন্য একটি নির্দিষ্ট লেআউট এবং অন্য কোনও "ডান-থেকে-বাম" ভাষার জন্য একটি জেনেরিক লেআউট প্রদান করতে চান, যেমন ফার্সি বা হিব্রু, তাহলে আপনি নিম্নলিখিত ডিরেক্টরিগুলি ব্যবহার করবেন: দ্রষ্টব্য: আপনার অ্যাপের জন্য ডান-থেকে-বামে লেআউট বৈশিষ্ট্যগুলি সক্ষম করতে, আপনাকে API লেভেল ১৭-এ যোগ করা হয়েছে। |
| সবচেয়ে ছোট প্রস্থ | sw<N>dpউদাহরণ: sw320dpsw600dpsw720dpইত্যাদি | একটি অ্যাপের জন্য উপলব্ধ স্ক্রিন এরিয়ার সবচেয়ে ছোট মাত্রা। বিশেষ করে, অ্যাপ উইন্ডোর উদাহরণস্বরূপ, যদি আপনার লেআউটের জন্য সর্বনিম্ন স্ক্রিন এরিয়ার মাত্রা সর্বনিম্ন 600 dp হওয়া প্রয়োজন হয়, তাহলে আপনি এই কোয়ালিফায়ার ব্যবহার করে একটি সাধারণ স্ক্রিনের আকার নির্ধারণের জন্য সবচেয়ে ছোট প্রস্থ ব্যবহার করা কার্যকর কারণ লেআউট ডিজাইনের ক্ষেত্রে প্রস্থ প্রায়শই চালিকাশক্তির বিষয়। একটি UI প্রায়শই উল্লম্বভাবে স্ক্রোল করে, তবে অনুভূমিকভাবে প্রয়োজনীয় ন্যূনতম স্থানের ক্ষেত্রে বেশ কঠিন সীমাবদ্ধতা রয়েছে। হ্যান্ডসেটের জন্য এক-প্যান লেআউট ব্যবহার করা হবে নাকি ট্যাবলেটের জন্য মাল্টিপ্যান লেআউট ব্যবহার করা হবে তা নির্ধারণের ক্ষেত্রে উপলব্ধ প্রস্থও গুরুত্বপূর্ণ বিষয়। সুতরাং, প্রতিটি ডিভাইসে সম্ভাব্য সর্বনিম্ন প্রস্থ কত তা নিয়ে আপনার সম্ভবত সবচেয়ে বেশি চিন্তা করা উচিত। একটি ডিভাইসের ক্ষুদ্রতম প্রস্থের জন্য স্ক্রিনের সাজসজ্জা এবং সিস্টেম UI বিবেচনা করা হয়। উদাহরণস্বরূপ, যদি ডিভাইসের স্ক্রিনে স্থায়ী UI উপাদান থাকে যা ক্ষুদ্রতম প্রস্থের অক্ষ বরাবর স্থানের জন্য দায়ী থাকে, তাহলে সিস্টেম ক্ষুদ্রতম প্রস্থকে প্রকৃত স্ক্রিনের আকারের চেয়ে ছোট বলে ঘোষণা করে, কারণ সেগুলি স্ক্রিন পিক্সেল যা আপনার UI এর জন্য উপলব্ধ নয়। সাধারণ স্ক্রিন আকারের জন্য আপনি এখানে কিছু মান ব্যবহার করতে পারেন:
যখন আপনার অ্যাপটি API লেভেল ১৩-এ যোগ করা হয়েছে। এছাড়াও এই কোয়ালিফায়ার ব্যবহার করে বিভিন্ন স্ক্রিনের জন্য ডিজাইনিং সম্পর্কে আরও তথ্যের জন্য, রেসপন্সিভ/অ্যাডাপ্টিভ ডিজাইন উইথ ভিউ দেখুন। |
| উপলব্ধ প্রস্থ এবং উচ্চতা | w<N>dph<N>dpউদাহরণ: w720dpw1024dph720dph1024dpইত্যাদি | রিসোর্সটি ব্যবহৃত ন্যূনতম উপলব্ধ স্ক্রিন প্রস্থ বা উচ্চতা ( মাল্টিপেন লেআউট ব্যবহার করবেন কিনা তা নির্ধারণের জন্য উপলব্ধ প্রস্থ এবং উচ্চতা প্রায়শই কার্যকর, কারণ এমনকি একটি ট্যাবলেট ডিভাইসেও আপনি প্রায়শই ল্যান্ডস্কেপের মতো পোর্ট্রেট ওরিয়েন্টেশনের জন্য একই মাল্টিপেন লেআউট চান না। সুতরাং, আপনি স্ক্রিনের আকার এবং ওরিয়েন্টেশন কোয়ালিফায়ার উভয়ই একসাথে ব্যবহার করার পরিবর্তে লেআউটের জন্য প্রয়োজনীয় ন্যূনতম প্রস্থ এবং/অথবা উচ্চতা নির্দিষ্ট করতে এগুলি ব্যবহার করতে পারেন। যখন আপনার অ্যাপ এই কনফিগারেশনের জন্য বিভিন্ন মান সহ একাধিক রিসোর্স ডিরেক্টরি সরবরাহ করে, তখন সিস্টেমটি ডিভাইসের বর্তমান স্ক্রিন প্রস্থের (অতিরিক্ত না করে) নিকটতমটি ব্যবহার করে। প্রকৃত স্ক্রিন প্রস্থ এবং নির্দিষ্ট প্রস্থের মধ্যে পার্থক্যগুলিকে প্রকৃত স্ক্রিন উচ্চতা এবং নির্দিষ্ট উচ্চতার মধ্যে পার্থক্যের সাথে যোগ করে নিকটতম নির্ধারণ করা হয়, যেখানে অনির্দিষ্ট উচ্চতা এবং প্রস্থের মান 0 থাকে। মানগুলি Window insets দ্বারা দখলকৃত এলাকা বাদ দেয়, তাই যদি ডিভাইসের ডিসপ্লের প্রান্তে স্থায়ী UI উপাদান থাকে, তাহলে প্রস্থ এবং উচ্চতার মানগুলি প্রকৃত স্ক্রিনের মাত্রার চেয়ে ছোট হয়, এমনকি যখন কিছু উল্লম্ব স্ক্রিন সজ্জা যা স্থির করা হয়নি (যেমন একটি ফোন স্ট্যাটাস বার যা পূর্ণ স্ক্রিনে লুকানো যেতে পারে) এখানে বিবেচনা করা হয় না , এবং টাইটেল বার বা অ্যাকশন বারের মতো উইন্ডো সজ্জাও এখানে বিবেচনা করা হয় না, তাই অ্যাপগুলিকে তাদের নির্দিষ্ট স্থানের চেয়ে কিছুটা ছোট স্থান মোকাবেলা করার জন্য প্রস্তুত থাকতে হবে। দ্রষ্টব্য: সিস্টেমটি এমন একটি রিসোর্স বেছে নেয় যা প্রস্থ এবং উচ্চতা উভয়ের সাথে মিলে যায়। অতএব, যে রিসোর্স উভয়কেই নির্দিষ্ট করে, সেই রিসোর্সকে কেবলমাত্র একটি বা অন্যটি নির্দিষ্ট করে এমন একটির চেয়ে বেশি পছন্দ করা হয়। উদাহরণস্বরূপ, যদি প্রকৃত স্ক্রিনটি 720 dp প্রস্থ এবং 1280 dp উচ্চ হয় এবং একটি রিসোর্স w720dp সহ যোগ্য হয় এবং অন্যটি w700dp-h1200dp হিসাবে যোগ্য হয়, তবে দ্বিতীয়টি বেছে নেওয়া হয় যদিও প্রথমটি এটি নির্দিষ্ট করে তার সাথে হুবহু মিল। API লেভেল ১৩-এ যোগ করা হয়েছে। এছাড়াও এই কোয়ালিফায়ার ব্যবহার করে বিভিন্ন স্ক্রিনের জন্য ডিজাইনিং সম্পর্কে আরও তথ্যের জন্য, রেসপন্সিভ/অ্যাডাপ্টিভ ডিজাইন উইথ ভিউ দেখুন। |
| পর্দার আকার | smallnormallargexlarge |
দ্রষ্টব্য: একটি আকারের যোগ্যতা ব্যবহার করার অর্থ এই নয় যে সংস্থানগুলি কেবল সেই আকারের স্ক্রিনের জন্য। যদি আপনি বর্তমান ডিভাইস কনফিগারেশনের সাথে আরও ভালভাবে মেলে এমন যোগ্যতা সহ বিকল্প সংস্থান সরবরাহ না করেন, তবে সিস্টেমটি যে কোনও সেরা সংস্থান ব্যবহার করতে পারে। সতর্কতা: যদি আপনার সমস্ত রিসোর্স বর্তমান স্ক্রিনের চেয়ে বড় আকারের কোয়ালিফায়ার ব্যবহার করে, তাহলে সিস্টেমটি সেগুলি ব্যবহার করবে না এবং রানটাইমে আপনার অ্যাপ ক্র্যাশ হয়ে যাবে। উদাহরণস্বরূপ, যদি সমস্ত লেআউট রিসোর্স API লেভেল ৪-এ যোগ করা হয়েছে। এছাড়াও আরও তথ্যের জন্য, স্ক্রিন সামঞ্জস্যের ওভারভিউ দেখুন। |
| স্ক্রিনের দিক | longnotlong |
API লেভেল ৪-এ যোগ করা হয়েছে। এটি সম্পূর্ণরূপে স্ক্রিনের আকৃতির অনুপাতের উপর ভিত্তি করে (একটি এছাড়াও |
| গোলাকার পর্দা | roundnotround |
API লেভেল ২৩-এ যোগ করা হয়েছে। এছাড়াও |
| ওয়াইড কালার গ্যামুট | widecgnowidecg |
API লেভেল ২৬-এ যোগ করা হয়েছে। এছাড়াও |
| উচ্চ গতিশীল পরিসর (HDR) | highdrlowdr |
API লেভেল ২৬-এ যোগ করা হয়েছে। এছাড়াও |
| স্ক্রিন ওরিয়েন্টেশন | portland |
ব্যবহারকারী যদি স্ক্রিনটি ঘোরান তাহলে এটি আপনার অ্যাপের জীবনকাল জুড়ে পরিবর্তিত হতে পারে। রানটাইম চলাকালীন এটি আপনার অ্যাপকে কীভাবে প্রভাবিত করে সে সম্পর্কে তথ্যের জন্য, হ্যান্ডেল কনফিগারেশন পরিবর্তনগুলি দেখুন। এছাড়াও |
| UI মোড | cardesktelevisionappliancewatchvrheadset |
API লেভেল ৮-এ যোগ করা হয়েছে; API ১৩-তে টেলিভিশন যোগ করা হয়েছে; API ২০-তে ঘড়ি যোগ করা হয়েছে। যখন ডিভাইসটি ডকে ঢোকানো হয় বা সরানো হয় তখন আপনার অ্যাপ কীভাবে প্রতিক্রিয়া জানাতে পারে সে সম্পর্কে তথ্যের জন্য, ডকিং অবস্থা নির্ধারণ এবং পর্যবেক্ষণ করুন এবং টাইপ করুন । ব্যবহারকারী যদি ডিভাইসটিকে ডকে রাখেন তাহলে আপনার অ্যাপের জীবনকাল জুড়ে এটি পরিবর্তিত হতে পারে। আপনি |
| রাত মোড | nightnotnight |
API লেভেল ৮-এ যোগ করা হয়েছে। যদি নাইট মোড অটো মোডে (ডিফল্ট) রাখা হয়, তাহলে আপনার অ্যাপের লাইফের সময় এটি পরিবর্তিত হতে পারে, এই ক্ষেত্রে দিনের সময়ের উপর নির্ভর করে মোড পরিবর্তিত হয়। আপনি |
| স্ক্রিন পিক্সেল ঘনত্ব (dpi) | ldpimdpihdpixhdpixxhdpixxxhdpinodpitvdpianydpinnn dpi |
ছয়টি প্রাথমিক ঘনত্বের মধ্যে একটি 3:4:6:8:12:16 স্কেলিং অনুপাত রয়েছে (tvdpi ঘনত্ব উপেক্ষা করে)। সুতরাং, ldpi-তে একটি 9x9 বিটম্যাপ হল mdpi-তে 12x12, hdpi-তে 18x18, xhdpi-তে 24x24, ইত্যাদি। দ্রষ্টব্য: ঘনত্বের যোগ্যতা ব্যবহার করার অর্থ এই নয় যে সংস্থানগুলি কেবল সেই ঘনত্বের স্ক্রিনের জন্য। যদি আপনি বর্তমান ডিভাইস কনফিগারেশনের সাথে আরও ভালভাবে মেলে এমন যোগ্যতার বিকল্প সংস্থান সরবরাহ না করেন, তবে সিস্টেমটি যে কোনও সেরা সংস্থান ব্যবহার করবে। বিভিন্ন স্ক্রিন ঘনত্ব কীভাবে পরিচালনা করবেন এবং বর্তমান ঘনত্বের সাথে মানানসই করার জন্য অ্যান্ড্রয়েড আপনার বিটম্যাপগুলি কীভাবে স্কেল করতে পারে সে সম্পর্কে আরও তথ্যের জন্য, স্ক্রিন সামঞ্জস্যতা ওভারভিউ দেখুন। |
| টাচস্ক্রিনের ধরণ | notouchfinger |
এছাড়াও |
| কীবোর্ডের উপলব্ধতা | keysexposedkeyshiddenkeyssoft |
যদি আপনি ব্যবহারকারী যদি একটি হার্ডওয়্যার কীবোর্ড খোলে, তাহলে এটি আপনার অ্যাপের জীবনকাল জুড়ে পরিবর্তিত হতে পারে। রানটাইম চলাকালীন এটি আপনার অ্যাপকে কীভাবে প্রভাবিত করে সে সম্পর্কে তথ্যের জন্য, হ্যান্ডেল কনফিগারেশন পরিবর্তনগুলি দেখুন। এছাড়াও কনফিগারেশন ক্ষেত্রগুলি দেখুন |
| প্রাথমিক টেক্সট ইনপুট পদ্ধতি | nokeysqwerty12key |
|
| নেভিগেশন কী প্রাপ্যতা | navexposednavhidden |
ব্যবহারকারী যদি নেভিগেশন কীগুলি প্রকাশ করে তবে এটি আপনার অ্যাপের জীবনকাল জুড়ে পরিবর্তিত হতে পারে। রানটাইম চলাকালীন এটি আপনার অ্যাপকে কীভাবে প্রভাবিত করে সে সম্পর্কে তথ্যের জন্য, হ্যান্ডেল কনফিগারেশন পরিবর্তনগুলি দেখুন। এছাড়াও |
| প্রাথমিক স্পর্শবিহীন নেভিগেশন পদ্ধতি | nonavdpadtrackballwheel |
এছাড়াও |
| প্ল্যাটফর্ম সংস্করণ (API স্তর) | উদাহরণ:v3v4v7ইত্যাদি | ডিভাইস দ্বারা সমর্থিত API স্তর। উদাহরণস্বরূপ, API স্তর 1 (Android 1.0 বা উচ্চতর সংস্করণ সহ ডিভাইস) এর জন্য |
দ্রষ্টব্য: অ্যান্ড্রয়েডের সকল ভার্সন সকল কোয়ালিফায়ার সমর্থন করে না। একটি নতুন কোয়ালিফায়ার ব্যবহার করলে পরোক্ষভাবে প্ল্যাটফর্ম ভার্সন কোয়ালিফায়ার যোগ হয় যাতে পুরোনো ডিভাইসগুলি এটি উপেক্ষা করতে পারে। উদাহরণস্বরূপ, w600dp কোয়ালিফায়ার ব্যবহার করলে স্বয়ংক্রিয়ভাবে v13 কোয়ালিফায়ার অন্তর্ভুক্ত হয়, কারণ available-width কোয়ালিফায়ার API লেভেল 13 তে নতুন ছিল। যেকোনো সমস্যা এড়াতে, সর্বদা ডিফল্ট রিসোর্সের একটি সেট অন্তর্ভুক্ত করুন ( কোনও কোয়ালিফায়ার ছাড়াই রিসোর্সের একটি সেট)। আরও তথ্যের জন্য, রিসোর্সের সাথে সেরা ডিভাইসের সামঞ্জস্য প্রদান সম্পর্কে বিভাগটি দেখুন।
যোগ্যতা অর্জনকারীর নামের নিয়ম
কনফিগারেশন কোয়ালিফায়ার নাম ব্যবহারের কিছু নিয়ম এখানে দেওয়া হল:
- আপনি ড্যাশ দ্বারা পৃথক করে একটি একক রিসোর্সের জন্য একাধিক কোয়ালিফায়ার নির্দিষ্ট করতে পারেন। উদাহরণস্বরূপ, ল্যান্ডস্কেপ ওরিয়েন্টেশনে US-English ডিভাইসের ক্ষেত্রে
drawable-en-rUS-landপ্রযোজ্য। - বাছাইপর্বের তালিকা অবশ্যই টেবিল ২- এ তালিকাভুক্ত ক্রমে হতে হবে।
- ভুল:
drawable-hdpi-port/ - সঠিক:
drawable-port-hdpi/
- ভুল:
- বিকল্প রিসোর্স ডিরেক্টরি নেস্ট করা যাবে না। উদাহরণস্বরূপ, আপনার
res/drawable/drawable-en/থাকতে পারে না। - মানগুলি কেস-ইনসেনসিটিভ। কেস-ইনসেনসিটিভ ফাইল সিস্টেমে সমস্যা এড়াতে রিসোর্স কম্পাইলার প্রক্রিয়াকরণের আগে ডিরেক্টরি নামগুলিকে ছোট হাতের অক্ষরে রূপান্তর করে। নামের যেকোনো বড় হাতের অক্ষর শুধুমাত্র পঠনযোগ্যতার সুবিধার জন্য।
- প্রতিটি কোয়ালিফায়ার টাইপের জন্য শুধুমাত্র একটি মান সমর্থিত। উদাহরণস্বরূপ, যদি আপনি স্পেন এবং ফ্রান্সের জন্য একই ড্রয়েবল ফাইল ব্যবহার করতে চান, তাহলে আপনার
drawable-es-fr/নামে একটি ডিরেক্টরি থাকতে পারে না । পরিবর্তে, আপনার দুটি রিসোর্স ডিরেক্টরি প্রয়োজন, যেমনdrawable-es/এবংdrawable-fr/, যাতে উপযুক্ত ফাইল থাকে। তবে, আপনাকে উভয় স্থানে ফাইলগুলিকে আসলে ডুপ্লিকেট করতে হবে না। পরিবর্তে, আপনি একটি রিসোর্সের জন্য একটি উপনাম তৈরি করতে পারেন, যেমন উপনাম রিসোর্স তৈরি করুন বিভাগে বর্ণিত হয়েছে।
এই কোয়ালিফায়ার সহ নামযুক্ত ডিরেক্টরিগুলিতে বিকল্প রিসোর্সগুলি সংরক্ষণ করার পরে, অ্যান্ড্রয়েড বর্তমান ডিভাইস কনফিগারেশনের উপর ভিত্তি করে স্বয়ংক্রিয়ভাবে আপনার অ্যাপে রিসোর্সগুলি প্রয়োগ করে। প্রতিবার যখন কোনও রিসোর্স অনুরোধ করা হয়, তখন অ্যান্ড্রয়েড অনুরোধকৃত রিসোর্স ফাইল ধারণকারী বিকল্প রিসোর্স ডিরেক্টরিগুলি পরীক্ষা করে, তারপর সেরা-মিলে যাওয়া রিসোর্সটি খুঁজে পায় ।
যদি কোনও নির্দিষ্ট ডিভাইস কনফিগারেশনের সাথে মেলে এমন কোনও বিকল্প রিসোর্স না থাকে, তাহলে অ্যান্ড্রয়েড সংশ্লিষ্ট ডিফল্ট রিসোর্স ব্যবহার করে—একটি নির্দিষ্ট রিসোর্স ধরণের জন্য রিসোর্সের সেট যাতে কোনও কনফিগারেশন কোয়ালিফায়ার অন্তর্ভুক্ত থাকে না।
উপনাম সম্পদ তৈরি করুন
যখন আপনার কাছে এমন একটি রিসোর্স থাকে যা আপনি একাধিক ডিভাইস কনফিগারেশনের জন্য ব্যবহার করতে চান কিন্তু আপনি এটিকে ডিফল্ট রিসোর্স হিসেবে প্রদান করতে চান না, তখন আপনাকে একই রিসোর্সটিকে একাধিক বিকল্প রিসোর্স ডিরেক্টরিতে রাখার প্রয়োজন নেই। পরিবর্তে, আপনি একটি বিকল্প রিসোর্স তৈরি করতে পারেন যা আপনার ডিফল্ট রিসোর্স ডিরেক্টরিতে সংরক্ষিত রিসোর্সের জন্য একটি উপনাম হিসেবে কাজ করে।
দ্রষ্টব্য: সমস্ত রিসোর্সে এমন কোনও ব্যবস্থা থাকে না যার মাধ্যমে আপনি অন্য রিসোর্সের জন্য একটি উপনাম তৈরি করতে পারেন। বিশেষ করে, অ্যানিমেশন, মেনু, raw, এবং xml/ ডিরেক্টরিতে থাকা অন্যান্য অনির্দিষ্ট রিসোর্সে এই বৈশিষ্ট্যটি থাকে না।
উদাহরণস্বরূপ, কল্পনা করুন আপনার একটি অ্যাপ আইকন আছে, icon.png , এবং বিভিন্ন লোকেলের জন্য এর একটি অনন্য সংস্করণ প্রয়োজন। তবে, দুটি লোকেল, English-Canadian এবং French-Canadian, একই সংস্করণ ব্যবহার করতে হবে। আপনাকে English-Canadian এবং French-Canadian উভয়ের জন্য রিসোর্স ডিরেক্টরিতে একই ছবি কপি করতে হবে না। পরিবর্তে, আপনি icon.png ছাড়া অন্য যেকোনো নাম ব্যবহার করে উভয়ের জন্য ব্যবহৃত ছবিটি সংরক্ষণ করতে পারেন, যেমন icon_ca.png , এবং এটিকে ডিফল্ট res/drawable/ ডিরেক্টরিতে রাখতে পারেন। তারপর res/drawable-en-rCA/ এবং res/drawable-fr-rCA/ তে একটি icon.xml ফাইল তৈরি করুন যা <bitmap> উপাদান ব্যবহার করে icon_ca.png রিসোর্সকে নির্দেশ করে। এটি আপনাকে PNG ফাইলের শুধুমাত্র একটি সংস্করণ এবং এটি নির্দেশ করে এমন দুটি ছোট XML ফাইল সংরক্ষণ করতে দেয়। বিস্তারিত জানার জন্য নিম্নলিখিত বিভাগগুলিতে উদাহরণগুলি দেখুন।
অঙ্কনযোগ্য
একটি বিদ্যমান ড্রয়েবলের একটি উপনাম তৈরি করতে, <drawable> উপাদানটি ব্যবহার করুন:
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="icon">@drawable/icon_ca</drawable> </resources>
যদি আপনি এই ফাইলটি icon.xml হিসেবে res/values-en-rCA/ মতো বিকল্প রিসোর্স ডিরেক্টরিতে সংরক্ষণ করেন, তাহলে এটি এমন একটি রিসোর্সে কম্পাইল হবে যা আপনি R.drawable.icon হিসাবে উল্লেখ করতে পারেন, কিন্তু আসলে এটি R.drawable.icon_ca রিসোর্সের একটি উপনাম, যা res/drawable/ এ সংরক্ষিত হয়।
লেআউট
একটি বিদ্যমান লেআউটের একটি উপনাম তৈরি করতে, <include> উপাদানটি ব্যবহার করুন, যা <merge> দিয়ে মোড়ানো:
<?xml version="1.0" encoding="utf-8"?> <merge> <include layout="@layout/main_ltr"/> </merge>
যদি আপনি এই ফাইলটি main.xml হিসেবে সংরক্ষণ করেন, তাহলে এটি একটি রিসোর্সে কম্পাইল হবে যা আপনি R.layout.main হিসেবে উল্লেখ করতে পারেন, কিন্তু আসলে এটি R.layout.main_ltr রিসোর্সের একটি উপনাম।
স্ট্রিং এবং অন্যান্য সহজ মান
একটি বিদ্যমান স্ট্রিং-এর একটি উপনাম তৈরি করতে, নতুন স্ট্রিংয়ের মান হিসেবে পছন্দসই স্ট্রিং-এর রিসোর্স আইডি ব্যবহার করুন:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello</string> <string name="hi">@string/hello</string> </resources>
R.string.hi রিসোর্সটি এখন R.string.hello এর একটি উপনাম।
অন্যান্য সাধারণ মানগুলি একইভাবে কাজ করে, যেমন রঙ:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="red">#f00</color> <color name="highlight">@color/red</color> </resources>
আপনার অ্যাপ রিসোর্স অ্যাক্সেস করুন
Once you provide a resource in your application, you can apply it by referencing its resource ID. All resource IDs are defined in your project's R class, which the aapt tool automatically generates.
When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in your res/ directory. For each type of resource, there is an R subclass, such as R.drawable for all drawable resources. And for each resource of that type, there is a static integer, for example, R.drawable.icon . This integer is the resource ID that you can use to retrieve your resource.
Although the R class is where resource IDs are specified, you don't need to look there to discover a resource ID. A resource ID is always composed of the following:
- The resource type : each resource is grouped into a "type," such as
string,drawable, andlayout. For more information about the different types, see Resource types overview . - The resource name , which is either the filename excluding the extension or the value in the XML
android:nameattribute, if the resource is a simple value, such as a string.
There are two ways you can access a resource:
- In code: using a static integer from a subclass of your
Rclass, such as:R.string.hello
stringis the resource type andhellois the resource name. There are many Android APIs that can access your resources when you provide a resource ID in this format. For more information, see the Access resources in code section. - In XML: using a special XML syntax that corresponds to the resource ID defined in your
Rclass, such as:@string/hello
stringis the resource type andhellois the resource name. You can use this syntax in an XML resource any place where a value is expected that you provide in a resource. For more information, see the Access resources from XML section.
Access resources in code
You can use a resource in code by passing the resource ID as a method parameter. For example, you can set an ImageView to use the res/drawable/myimage.png resource using setImageResource() :
কোটলিন
val imageView = findViewById(R.id.myimageview) as ImageView imageView.setImageResource(R.drawable.myimage)
জাভা
ImageView imageView = (ImageView) findViewById(R.id.myimageview); imageView.setImageResource(R.drawable.myimage);
You can also retrieve individual resources using methods in Resources , which you can get an instance of with getResources() .
বাক্য গঠন
Here's the syntax to reference a resource in code:
[<package_name>.]R.<resource_type>.<resource_name>
<package_name>is the name of the package in which the resource is located (not required when referencing resources from your own package).-
<resource_type>is theRsubclass for the resource type. -
<resource_name>is either the resource filename without the extension or theandroid:nameattribute value in the XML element, for simple values.
For more information about each resource type and how to reference them, see Resource types overview .
ব্যবহারের ক্ষেত্রে
There are many methods that accept a resource ID parameter, and you can retrieve resources using methods in Resources . You can get an instance of Resources using Context.getResources() .
Here are some examples of accessing resources in code:
কোটলিন
// Load a background for the current screen from a drawable resource. window.setBackgroundDrawableResource(R.drawable.my_background_image) // Set the Activity title by getting a string from the Resources object, because // this method requires a CharSequence rather than a resource ID. window.setTitle(resources.getText(R.string.main_title)) // Load a custom layout for the current screen. setContentView(R.layout.main_screen) // Set a slide in animation by getting an Animation from the Resources object. flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_in)) // Set the text on a TextView object using a resource ID. val msgTextView = findViewById(R.id.msg) as TextView msgTextView.setText(R.string.hello_message)
জাভা
// Load a background for the current screen from a drawable resource. getWindow().setBackgroundDrawableResource(R.drawable.my_background_image) ; // Set the Activity title by getting a string from the Resources object, because // this method requires a CharSequence rather than a resource ID. getWindow().setTitle(getResources().getText(R.string.main_title)); // Load a custom layout for the current screen. setContentView(R.layout.main_screen); // Set a slide in animation by getting an Animation from the Resources object. flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_in)); // Set the text on a TextView object using a resource ID. TextView msgTextView = (TextView) findViewById(R.id.msg); msgTextView.setText(R.string.hello_message);
Caution: Don't modify the R.java file by hand. It is generated by the aapt tool when your project is compiled. Any changes are overridden next time you compile.
Access resources from XML
You can define values for some XML attributes and elements using a reference to an existing resource. You often do this when creating layout files, to supply strings and images for your widgets.
For example, if you add a Button to your layout, use a string resource for the button text:
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/submit" />
বাক্য গঠন
Here is the syntax to reference a resource in an XML resource:
@[<package_name>:]<resource_type>/<resource_name>
<package_name>is the name of the package in which the resource is located (not required when referencing resources from the same package).-
<resource_type>is theRsubclass for the resource type. -
<resource_name>is either the resource filename without the extension or theandroid:nameattribute value in the XML element, for simple values.
For more information about each resource type and how to reference them, see Resource types overview .
ব্যবহারের ক্ষেত্রে
In some cases, you must use a resource for a value in XML, such as to apply a drawable image to a widget, but you can also use a resource in XML any place that accepts a simple value. For example, if you have the following resource file that includes a color resource and a string resource :
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="opaque_red">#f00</color> <string name="hello">Hello!</string> </resources>
You can use these resources in the following layout file to set the text color and text string:
<?xml version="1.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@color/opaque_red" android:text="@string/hello" />
In this case, you don't need to specify the package name in the resource reference, because the resources are from your own package. To reference a system resource, you need to include the package name, as shown in the following example:
<?xml version="1.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@android:color/secondary_text_dark" android:text="@string/hello" />
Note: Always use string resources, so that your application can be localized for other languages. For information about creating alternative resources (such as localized strings), see Provide alternative resources . For a complete guide to localizing your application for other languages, see Localize your app .
You can even use resources in XML to create aliases. For example, you can create a drawable resource that is an alias for another drawable resource:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/other_drawable" />
This sounds redundant, but can be very useful when using alternative resource. For more information, see the section about creating alias resources .
Reference style attributes
A style attribute resource lets you reference the value of an attribute in the currently applied theme. Referencing a style attribute lets you customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hardcoded value. Referencing a style attribute essentially says, "Use the style that is defined by this attribute in the current theme."
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the "at" symbol ( @ ), use a question mark ( ? ). The resource type portion is optional. So the reference syntax is as follows:
?[<package_name>:][<resource_type>/]<resource_name>
For example, here's how you can reference an attribute to set the text color to match the secondary text color of the system theme:
<EditText id="text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="?android:textColorSecondary" android:text="@string/hello_world" />
Here, the android:textColor attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary style attribute as the value for android:textColor in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type, which is ?android:attr/textColorSecondary . You can exclude the attr type.
Access original files
While uncommon, you might need access your original files and directories. If you do, then saving your files in res/ won't work for you, because the only way to read a resource from res/ is with the resource ID. Instead, you can save your resources in the assets/ directory.
Files saved in the assets/ directory are not given a resource ID, so you can't reference them through the R class or from XML resources. Instead, you can query files in the assets/ directory like a normal file system and read raw data using AssetManager .
However, if all you require is the ability to read raw data (such as a video or audio file), then save the file in the res/raw/ directory and read a stream of bytes using openRawResource() .
Access platform resources
Android contains a number of standard resources, such as styles, themes, and layouts. To access these resources, qualify your resource reference with the android package name. For example, Android provides a layout resource you can use for list items in a ListAdapter :
কোটলিন
listAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, myarray)
জাভা
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myarray));
In this example, simple_list_item_1 is a layout resource defined by the platform for items in a ListView . You can use this instead of creating your own layout for list items.
Provide the best device compatibility with resources
For your app to support multiple device configurations, it's very important that you always provide default resources for each type of resource that your app uses.
For example, if your app supports several languages, always include a values/ directory (in which your strings are saved) without a language and region qualifier . If you instead put all your string files in directories that have a language and region qualifier, then your app crashes when run on a device set to a language that your strings don't support.
As long as you provide default values/ resources, then your app runs properly, even if the user doesn't understand the language it presents. It's better than crashing.
Likewise, if you provide different layout resources based on the screen orientation, pick one orientation as your default. For example, instead of providing layout resources in layout-land/ for landscape and layout-port/ for portrait, leave one as the default, such as layout/ for landscape and layout-port/ for portrait.
Providing default resources is important not only because your app might run on a configuration you hadn't anticipated, but also because new versions of Android sometimes add configuration qualifiers that older versions don't support. If you use a new resource qualifier, but maintain code compatibility with older versions of Android, then when an older version of Android runs your app, it crashes if you don't provide default resources, because it can't use the resources named with the new qualifier.
For example, if your minSdkVersion is set to 4, and you qualify all of your drawable resources using night mode ( night or notnight , which were added in API level 8), then an API level 4 device can't access your drawable resources and crashes. In this case, you probably want notnight to be your default resources, so exclude that qualifier and put your drawable resources in either drawable/ or drawable-night/ .
In short, to provide the best device compatibility, always provide default resources for the resources your app needs to perform properly. Then create alternative resources for specific device configurations using configuration qualifiers.
There is one exception to this rule: If your app's minSdkVersion is 4 or greater, you don't need default drawable resources when you provide alternative drawable resources with the screen density qualifier. Even without default drawable resources, Android can find the best match among the alternative screen densities and scale the bitmaps as necessary. However, for the best experience on all types of devices, provide alternative drawables for all three types of density.
How Android finds the best-matching resource
When you request a resource for which you provide alternatives, Android selects which alternative resource to use at runtime, depending on the current device configuration. To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:
drawable/ drawable-en/ drawable-fr-rCA/ drawable-en-port/ drawable-en-notouch-12key/ drawable-port-ldpi/ drawable-port-notouch-12key/
And assume the following is the device configuration:
Locale = en-GB
Screen orientation = port
Screen pixel density = hdpi
Touchscreen type = notouch
Primary text input method = 12key
By comparing the device configuration to the available alternative resources, Android selects drawables from drawable-en-port .
The system arrives at its decision for which resources to use with the following logic:

Figure 2. Flowchart of how Android finds the best-matching resource.
- Eliminate resource files that contradict the device configuration.
The
drawable-fr-rCA/directory is eliminated, because it contradicts theen-GBlocale.drawable/ drawable-en/
drawable-fr-rCA/drawable-en-port/ drawable-en-notouch-12key/ drawable-port-ldpi/ drawable-port-notouch-12key/Exception: Screen pixel density is the one qualifier that is not eliminated due to a contradiction. Even though the screen density of the device is hdpi,
drawable-port-ldpi/isn't eliminated because every screen density is considered to be a match at this point. For information, see Screen compatibility overview . - Find the next-highest-precedence qualifier in the list ( table 2 ). (Start with MCC.)
- Do any of the resource directories include this qualifier?
- If no, return to step two and look at the next qualifier. In this example, the answer is "no" until the language qualifier is reached.
- If yes, continue to step four.
- Eliminate resource directories that don't include this qualifier. In this example, the system next eliminates all the directories that don't include a language qualifier:
drawable/drawable-en/ drawable-en-port/ drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/Exception: If the qualifier in question is screen pixel density, Android selects the option that most closely matches the device screen density. In general, Android prefers scaling down a larger original image to scaling up a smaller original image. For more information, see Screen compatibility overview .
- Repeat steps two, three, and four until only one directory remains. In this example, screen orientation is the next qualifier for which there are any matches. So, resources that don't specify a screen orientation are eliminated:
drawable-en/drawable-en-port/drawable-en-notouch-12key/The remaining directory is
drawable-en-port.
Though this procedure is executed for each resource requested, the system optimizes some aspects of it. One such optimization is that once the device configuration is known, it might eliminate alternative resources that can never match. For example, if the configuration language is English, then any resource directory that has a language qualifier set to something other than English is never included in the pool of resources checked (though a resource directory without the language qualifier is still included).
When selecting resources based on the screen size qualifiers, the system uses resources designed for a screen smaller than the current screen if there are no resources that better match. For example, a large-size screen uses normal-size screen resources if necessary.
However, if the only available resources are larger than the current screen, the system doesn't use them and your app crashes if no other resources match the device configuration. This happens, for example, if all layout resources are tagged with the xlarge qualifier, but the device is a normal-size screen.
Note: The precedence of the qualifier (in table 2 ) is more important than the number of qualifiers that exactly match the device. In the preceding example, at step four the last choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen type, and input method), while drawable-en has only one parameter that matches (language). However, language has a higher precedence than these other qualifiers, so drawable-port-notouch-12key is eliminated.