We're developing an android application that has several different tabs. We've been trying to apply a theme to entire application, and we've also tried applying a theme to specific activities. Neither has any effect.
I have this style-file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="recapmain">
<item name="android:buttonStyle">#style/recapButton</item>
<item name="android:textViewStyle">#style/recapText</item>
</style>
<style name="recapButton" parent="android:style/Widget.Button">
<item name="android:textSize">30sp</item>
<item name="android:background">#FF0000</item>
</style>
<style name="recapText">
<item name="android:textSize">30dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
The application tag in the manifest file looks like this:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/recapmain">
<activity android:name="appname"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This doesn't work. The application simply does not react to the theme. If I set a specific view to use one of the styles, it's works perfectly. So, I can do this in the xml file for an activity:
<Button
android:id="#+id/OverviewButtonYears"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/years"
android:onClick="years"
style="#style/recapButton"
/>
That will style the button appropriately.
we've also tried applying the theme to a specific activity tag, with no result.
Now, what does work, is removing the intent-filter-tag from the application tag, and putting it in an activity tag, like this:
<activity android:name=".PolicyTab" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
That starts the specific activity only, and it does have the appropriate theme.
My question then, is, why? We've gussed that it has something to do with the tabs, since starting only one activity enables the theme. What do we have to do to get it to work with tabs?
If you wany your main application theme to be android:theme="#android:style/Theme.NoTitleBar" with customized control styles, then you should extend that theme with your preferences:
<style name="recapmain" parent="#android:style/Theme.NoTitleBar">
This line will adopt the styles of the parent theme into recapmain, and inside you can write your own preferences (as you already have for buttonStyle and textViewStyle).
Inside your androidManifest.xml you set the application theme to your custom style:
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#style/recapmain">
Update
Your styles.xml should contain:
<style name="recapmain" parent="#android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">#style/recapButton</item>
<item name="android:textViewStyle">#style/recapText</item>
</style>
<style name="recapButton" parent="android:style/Widget.Button">
<item name="android:textSize">30sp</item>
<item name="android:background">#FF0000</item>
</style>
<style name="recapText" parent="android:style/Widget.TextView">
<item name="android:textSize">30dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Related
I keep seeing my domain name in the ToolBar in the past I would just use the Manifest file with this line android:label="#string/app_name" I can accomplish this in the ActivityMain.java with title. but would prefer to use the xml and strings concept. The only thing I have done different is create a custom style in the styles.xml for some TextView widgets tools v 24.0.2 V7 24.2.0 code posted
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!--<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>-->
<style name="MyStyle" parent="AppTheme">
<item name="android:textColor">#f10909</item>
<item name="android:textSize">20sp</item>
<item name="android:width">190dp</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXX.newstyletest">
<application>
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:title="what the Hell"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:theme="#style/MyStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Is this an issue because of the custom style of has something changed ?
or what the heck am I doing wrong
You're going to scream when you SEE what is wrong if you look real close at you AndroidManifest.xml file you will see you have a situation where the code below the is UNREACHABLE because you have a closing brace behind the word application So just remove that > and life will be good
My theme is not working I have seen this How do I change the background color of the ActionBar of an ActionBarActivity using XML? but not working
still grey only SplahScreen activity changed but MainActivity extend FragmentActivity not:
Manifest:
<application
android:largeHeap="true"
android:name="asasdsd.asdasdas"
android:allowBackup="true"
android:icon="#drawable/ic_launcher2"
android:label="#string/app_name"
android:theme="#style/MyTheme"
>
<activity
android:name="app.sultan.sdcinfo.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="app.sultan.sdcinfo.MainActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme"
>
</activity>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />`
I have localization and add theme file in every Language also in value-11 still not changed:Theme.xml
`<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#262626</item>
</style>`
Tried with getActionbar.setBackgroundDrawable(new ColorDrawable("COLOR"));
please look my project structure:splash screen activity then Main activity wich include navigation drawer with fragments in activitis color background changed but not in the fragment
You could not be able to change the actionbar background color because you are not using Widget.Holo.Light.ActionBar.Solid.Inverse as the parent of MyActionBar
use
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"
instead of
parent="#android:style/Widget.Holo.Light.ActionBar
So your theme.xml would be like,
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#262626</item>
</style>
</resources>
Source : Customize ActiobBar Background (Official Documentation)
I would like to set the background of my activity to an image without setting the ActionBar background to the same image. I started with a "Hello, world" application with EditText, Button and an ActionBar and the following styles added...
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:background">#drawable/bg20140804_090625_640_960</item>
</style>
<style name="MyActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#android:color/transparent</item>
</style>
</resources>
Here is the application manifest...
<uses-sdk android:minSdkVersion="11" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.company.android.mysecondapplication.MainActivity" />
</activity>
</application>
The problem I am seeing is that the background image is shown in the ActionBar (distorted). I would like the ActionBar to be semi-transparent and for the background of the Activity to show through.
This is what it looks like, notice the ActionBar background. Also notice the icons are way over to the left when normally (i.e., without the custom style), they would be to the right.
Lastly, if you change the styles to the following, the application looks like the tutorial.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
Thanks
Change
<item name="android:background">#color/your_color</item>
with
<item name="android:windowBackground">#color/your_color</item>
You can use #drawable/your_drawable of course.
Set the background image to the layout of your Activity and not to the Theme, that will result in only the Activity having the image as the background.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bg20140804_090625_640_960" >
</LinearLayout>
I have following style definitions in my res/values/style.xml file:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="MainActivity" parent="AppTheme">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
And following code in manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:theme="#style/MainActivity"
android:name="com.example.mygateway.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>
I expect that textColor #f0f will be applied to MainActivity activity, but it isn't.
Neither textColor no other items i tried are applied.
Actually the only AppTheme is applied to the activity and the whole application.
I'am a beginner in android development. What I do wrong?
Please help.
Thanks!
As official docs state:
"If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:"
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textColor">#fff</item>
<item name="android:textSize">12sp</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:textColor">#f0f</item>
<item name="android:background">#color/black</item>
</style>
and
<activity android:theme="#style/AppTheme.MainActivity"
...>
...
</activity>`
If I define a custom theme using styles:
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">#dimen/title_bar_height</item>
<item name="android:windowTitleBackgroundStyle">#drawable/titilebar_bg</item>
<item name="android:windowBackground">#drawable/bg_page</item>
</style>
and also I have a special titlebar.xml which defines my title bar (buttons, icons, text etc) is there a way to set this layout as default layout for title bar in styles (like a default behavior for all activities)?
So that I wouldn't have to add the following code in every single activity (all activities actually):
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
The only way I can see is to subclass Activity to inherit method which would make requestWindowFeature() among with onCreate()/setContentView(). But its not exactly what I'm asking about.
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#000000</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
Mainfest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme" >
<activity
android:name=".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>