Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

coding style - How to add multiple theme attributes to the same activity on Android Manifest?

I have an android manifest with an activity that I want to apply to styles to:

 <activity android:label="@string/app_name" android:name="Language" android:theme="@android:style/Theme.NoTitleBar>

Is how it looks right now, but while keeping the NoTitleBar attribute, I would like to add this attribute as well:

android:style/Theme.Light"

But I'm just so new to Android that I can't figure it out.

Please help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot have more than one theme applied at once in your manifest.

I believe there is a theme Theme.Light.NoTitleBar that will do what you want - but I will show you below how you can easily do this yourself and customize more.

What you need to do is create a theme which has either Theme.NoTitleBar or Theme.Light as it's parent and customizes the bits you want -- in this case the easiest way is to create a theme with Theme.Light as it's parent and just hide the title bar (rather than have the Theme.NoTitleBar as the parent and then have to make everything light which is much harder!).

You can do this with the following code in your themes.xml file in the values folder:

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

    <!-- use the Android Light theme as the base for our own theme -->
    <style name="MySuperTheme" parent="@android:style/Theme.Light">

        <!-- hide the Window Title -->
        <item name="android:windowNoTitle">true</item>

        <!-- You could change the scrollbar, checkbox style, anything! -->
    </style>

</resources>

Then use android:theme="@style/MySuperTheme" for your activity (or you could even apply it to your whole application by placing it on the application element -- if you apply a style to an individual activity and have one set for the whole application as well then the style of the individual activity will be the one shown).

Take a look at the Android themes.xml for a list of all the things you can customize in your own theme.

You can also look at all of the Android styles to see how they are done.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...