Custom Android themes

Source: Internet
Author: User

In androidmanifest. XML, you can define the topic of the entire app or the topic of a single activity. The following example defines a topic for the application and activity respectively:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"    <application android:theme="custom_application_theme"      <activity android:name=".Activity"android:theme="custom_activity_theme"/>    </application></manifest>


The next question is to define your own theme. In fact, theme is just a style set with a wider scope, therefore, the format of theme and style is the same. If you use eclipse to create a blank project of more than 4.0, you can see the following androidmanifest. xml:

    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.yg.xesam.net.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application>

View the content of @ style/apptheme to see the final style definition (the system themes file is placed in/RES/values/themes. xml of the SDK platform ).

Custom theme can be defined in styles. xml. For convenience, you can also define themes. XML as follows:

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="custom_application_theme" parent="android:Theme.Light"></style>    <style name="custom_activity_theme" parent="custom_application_theme"></style></resources>


For details, refer to the themes. xml file that comes with the SDK. For example, you can define the full screen of the program and whether there is a title bar based on inheriting the parent (Android: theme. Light) style.
In the following example:
Custom_application_theme has no title bar and is full screen. custom_activity_theme overwrites the Android: windownotitle attribute of custom_application_theme. Therefore, custom_activity_theme is full screen but the title bar is retained.

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="custom_application_theme" parent="android:Theme.Light">        <item name="android:windowNoTitle">true</item>        <item name="android:windowFullscreen">true</item>    </style>    <style name="custom_activity_theme" parent="custom_application_theme">        <item name="android:windowNoTitle">false</item>    </style></resources>

 

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.