Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize skin for applications by Android

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this article, the editor introduces in detail "how to customize the skin for the application by Android". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to customize the skin for the application by Android" can help you solve your doubts.

Let's start with the train of thought:

1) skin, that is, related resource files are placed separately in a project, a kind of skin, an engineering file. A project includes more than N resource files, and the relationship of resources among multiple projects is exactly the same, such as file name, resource ID, etc. Different may be the picture resources, style and other settings are not the same.

Skin engineering configures android:sharedUserId= "com.eric.skinmain" in AndroidManifest.xml.

Indicates that com.eric.skinmain is allowed to access the resource files in the project. Com.eric.skinmain is the package name of the main project

3) the main project passes this.createPackageContext ("com.eric.blackskin", Context.CONTEXT_IGNORE_SECURITY)

Get the Context corresponding to com.eric.blackskin, and then you can access any resource in com.eric.blackskin through the returned context object, just as you can access your own resources.

Note: remember to install the corresponding apk file for skin engineering first.

Public class main extends Activity {/ * * Called when the activity is first created. * / private LinearLayout showBg; private Button btn; private Context green_skin_Context = null; private Context black_skin_Context = null; int flag = 0; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.main) ShowBg = (LinearLayout) findViewById (R.id.linear_layout_1); try {green_skin_Context = this.createPackageContext ("com.eric.greenskin", Context.CONTEXT_IGNORE_SECURITY);} catch (NameNotFoundException e) {e.printStackTrace () } try {black_skin_Context = this.createPackageContext ("com.eric.blackskin", Context.CONTEXT_IGNORE_SECURITY);} catch (NameNotFoundException e) {e.printStackTrace () } btn = (Button) findViewById (R.id.btn_change_skin) Btn.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {if (flag = = 0) {showBg.setBackgroundDrawable (green_skin_Context) .getResources () .getDrawable (R.drawable.bg)) Btn.setBackgroundDrawable (green_skin_Context .getResources (). GetDrawable (R.drawable.btn_normal)); flag = 1 } else if (flag = = 1) {showBg.setBackgroundDrawable (black_skin_Context .getResources () .getDrawable (R.drawable.bg)) Btn.setBackgroundDrawable (black_skin_Context .getResources (). GetDrawable (R.drawable.btn_normal)); flag = 0 }) }} after reading this, the article "how to customize skin for applications with Android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report