Android 2.x version uses the theme of 4.x

Source: Internet
Author: User

Now, And most Android developers use the SDK version of 2.x when they develop the Android app. In order to be compatible with 2.x mobile phone this is understandable, but the most troubling is the 2.x version of the theme is in too ugly, this is the launch of Android just consider the practical, and did not take into account the aesthetics, and now up to the operating system to the application software is a beautiful interface, Comfortable operation experience as the premise, then whether it can be compatible with 2.x and can use the theme of 4.x style it? The answer, of course, is there!

Sometimes when we install an app, we will see that support the minimum version for 2.1,2.2, etc., but open the app its main style is really 4.x, we may think so, since it can support 2.1,2.2 that it uses the SDK version should be 2.x, but why the theme style is really 4.x? The truth is simple, Since is the theme of the 4.x style, it must be compiled with the SDK version of 4.x, in order to achieve this effect, you can dynamically judge the current version of the system in the code, if you use the 2.x theme style below 11, if more than 11 is using 4.x theme style, you can create a baseactivity, judge the code into Among them, the other activity all inherit baseactivity, the main code is as follows:

if (Build.VERSION.SDK_INT < build.version_codes. Honeycomb) {            setTheme (Android. R.style.theme_black_notitlebar);        } else{            SetTheme (android. r.style.theme_holo_light);        } Requestwindowfeature (window.feature_no_title);//Remove the title bar
The code is placed in the OnCreate method, Super.oncreate (Savedinstancestate) before, and the minimum supported version is declared in the Androidmanifest.xml file, typically 7, or 8:

<USES-SDK android:minsdkversion= "7"/>
Finally, some students after using this method, open the app for a moment will see a black interface with the title bar a flash, so that you can first ina default theme can be defined in Androidmanifest.xml:

After that, we can no longer use the 2.x SDK to compile the project.

It is also important to note that if the project uses tabactivity, it needs to be judged in the same way in your tabmainactivity.




Android 2.x version uses the theme of 4.x

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.