Custom Theme not applying in FragmentActivity - android

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)

Related

I need to remove my top app bar in specific Activity

I am a beginner of android,Kotlin,
I don't know how to remove the top app bar in a specific and all activities.
I have a splash screen and a new activity
Below is my style's code,I already imported a material design in styles.xml
I don't know what is the way to remove the top app bar in styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shanjostech.newsample">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Main_Screen"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Add theme attribute to the activity where you want to hide appbar in manifest file
<activity
android:name="com.mvvm.Activity"
android:label="#string/app_name"
android:theme="#style/NewTheme">
</activity>
then create a new theme in style.xml with parent as Theme.AppCompat.NoActionBar
<style name="NewTheme" parent="Theme.AppCompat.NoActionBar">
</style>
This question is already answered here:-
How to remove it from all activities
How to remove it from specific activity
In Case if none of them work fine for you then try this:-
For specific activity,
Set theme in manifest file as mentioned below:-
<activity android:name=".activity.ContinueLoginActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait" />
Programmatically :-
Kotlin:
supportActionBar?.hide()
Java:
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
for remove it from all activities change .DarkActionBar by .NoActionBar in style.xml file:-
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

how to set image to background n text color of action bar?

I want so set backgroung image to actionbar of main activity and all activities too and also want to chnage text color of text of action bar
i tried this code but it giving me error
plz help me
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
</resources>`
manifest code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.navigationd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="OLXA"
android:theme="#style/AppThe" >
<activity
android:name="com.example.hp.navigationd.MainActivity"
android:label="OLXA" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.hp.navigationd.post_ad"
android:label="#string/Ad_Details"
android:parentActivityName="com.example.hp.navigationd.MainActivity" />
<activity android:name="com.example.hp.navigationd.My_account" />
<activity android:name="com.example.hp.navigationd.My_fav" />
<activity android:name="com.example.hp.navigationd.My_ads" />
<activity android:name="com.example.hp.navigationd.My_chats" />
<activity android:name="com.example.hp.navigationd.Rules" />
<activity android:name="com.example.hp.navigationd.Help" />
<activity android:name="com.example.hp.navigationd.About_us" />
</application>
</manifest>
Try this,
Insted of using,
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
use this,
<style name="AppThe" parent="#android:style/Theme.Holo.Light.DarkActionBar">
Check out the below style.
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<item name="background">#drawable/actionbar_background</item>
</style>
Here you need to use both you both android:actionBarStyle and actionBarStyle as well as android:background and background items. The former is for newer versions of android that support ActionBar natively. The latter is for older android versions.
About the error:
You can not use "#android:style/Theme.Holo.Light" with AppCompatActivity

How to change the launcher activity name and icon and keep the app name and icon?

I would like to have different title bar icons and names in the different activities, but not to change the app name or icon. The first activity should not have a title name.
This is what I have in the AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:name="" <!-- there should be no title here -->
android:icon="#drawable/custom_icon"
android:windowSoftInputMode="stateHidden|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:icon="#drawable/another_custom_icon"
android:label="MainTitle" >
</activity>
</application>
Apparently Android uses the name and the icon of the first activity for the app name and icon.
I know that I can put this line of code in the onCreate of the activity:
getActionBar().setTitle("");
But it is also shown during load, until it gets removed.
This is the styles.xml file:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/actionBarCustomization</item>
</style>
<style name="actionBarCustomization" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FFFFFF</item>
<item name="android:titleTextStyle">#style/actionBarTextColor</item>
</style>
<style name="actionBarTextColor" parent="#android:style/TextAppearance">
<item name="android:textColor">#000000</item>
</style>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:screenOrientation="portrait"
<!-- This the name on Activity so put there the name of your MainActivity i.e com.example.MainActivity -->
android:name="NAME OF YOU LAUNCHER ACTIVITY"
android:icon="#drawable/custom_icon"
android:theme="#style/Theme.NoActionBarTitle"
android:windowSoftInputMode="stateHidden|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:icon="#drawable/another_custom_icon"
android:label="MainTitle" >
</activity>
Style.xml
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
</style>
<style name="Theme.NoActionBarTitle" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/NoActionBarTitle.ActionBar</item>
</style>
<style name="NoActionBarTitle.ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<<item name="android:displayOptions">showHome|useLogo</item>
</style>
After That you can show the title of activity if you want to By using method.
getActionBar().setDisplayShowTitleEnabled(true);
For Those who are using appcompat support library.I mean there activites are extending from AppCompatActivity use the below style file
Style.xml if you are using appcompat
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="Theme.NoActionBarTitle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/NoActionBarTitle.ActionBar</item>
<item name="android:actionBarStyle">#style/NoActionBarTitle.ActionBar</item>
</style>
<style name="NoActionBarTitle.ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
</style>

Setting ONLY the Activity Background and not the Action Bar Background

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>

Tabs interfering with application- and activity themes

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>

Categories

Resources