How to create trasparent activity when i click Floating action button - android

First sorry for my bad English ,I am creating activity within that activity , i create floating action button ,when i click Floating Action Button on click action i show one activity it working fine but how to change my activity to transparent activity with no action bar
i change manifest file but getting some errors
mainifest file
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_fullscreen"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.aa.bunny.aabunny.Main2Activity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name=".ScrollingActivity"
android:label="#string/title_activity_scrolling"
android:theme="#style/AppTheme.NoActionBar" >
</activity>
<activity android:name=".Main22Activity" >
</activity>
</application>
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
<style name="Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>

Change activity theme to achieve transparency.
create a style like this
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
and use this in manifest
<activity android:name=".TransparentActivity" android:theme="#style/Theme.Transparent">
Happy coding...

You can apply theme like..
android:theme="#android:style/Theme.Translucent"
Or else you can also create your own theme in style..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
You can also Set background of the activity as a transparent png image or a transparent color code

Related

android:theme parameter inside manifest ignored

I have AppTheme style in my styles.xml file. In manifest file i choose it like application theme.
I want to login activity unique style and I created login style, and set it in manifest. But it is not working, LoginActivity still takes AppTheme.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:name=".application.TrainerApp"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".activities.login.LoginActivity"
android:theme="#style/LoginTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="LoginTheme" parent="#style/AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Try like this :-
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#ff0</item>
<item name="colorPrimaryDark">#0ff</item>
<item name="colorAccent">#f0f</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Instead of :-
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="LoginTheme" parent="#style/AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Remove android:theme="#style/AppTheme" from your application tag and apply theme for each activity separately. For more detail, please see my link: http://androidkeeda.com/android-working-on-material-theme

Change AppTheme dynamically

Goal: I want to allow user to change the color theme of my app.
Themes (styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="AppTheme.Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="android:statusBarColor">#color/indigoColorPrimaryDark</item>
</style>
<style name="AppTheme.Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
<item name="android:statusBarColor">#color/blueColorPrimaryDark</item>
</style>
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<!-- some other colors -->
</resources>
As you can see, I have the main theme AppTheme that as a default color ("indigo").
I have three other themes FullScreen, MainActivity and SearchActivity that derive from AppTheme, and then colors themes.
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.superbstudios.reportnote">
<uses-permission android:name="android.permission.INTERNET" />
<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=".SignInActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.FullScreen" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:label=""
android:theme="#style/AppTheme.SearchActivity"
android:windowSoftInputMode="stateVisible" />
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/AppTheme" />
<activity
android:name=".GuideActivity"
android:label="#string/title_activity_guide"
android:theme="#style/AppTheme" />
</application>
</manifest>
Now, only SignInActiviy, MainActivity and SearchActivity has their own themes, the other activity (also application) has AppTheme.
What I do: I create a BaseActivity class, and all activity extend this class.In BaseActivity in onCreate method before super declaration I use this code to change color theme:
setTheme(R.style.AppTheme_Red);
Problem: This code change the theme for all activity and also for SignInActiviy, MainActivity and SearchActivity that needs a different theme.
I don't know if the colors theme are useful.
The only things i want is to change the AppTheme colors like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
So, what I have to do to change colors of my app?
I solved it by changing styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.MainActivity">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.SearchActivity">
<item name="android:statusBarColor">#android:color/darker_gray</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
<!-- Colors -->
<style name="Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
</style>
<style name="Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
</style>
<style name="Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
</style>
</resources>
And in my BaseActivity i use this code:
getTheme().applyStyle(R.style.Blue, true);
Referenced to the comment
I'll answer by taking Red color as an example
If you only want to change the colorPrimary then keep only it.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
</style>
Other wise create two themes for Red color. One with status bar color and other inheriting that with transparent status bar.
<style name="AppTheme.Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
<item name="android:statusBarColor">#color/redColorPrimaryDark</item>
</style>
<style name="AppTheme.RedTransparentStatus" parent="AppTheme.Red>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
So if you want status bar to transparent you can set the second theme or else the first.
From my understanding, you want to keep the default "Indigo" color for
SignInActivity, MainActivity, SearchActivity.
Todo so inherit the relevant themes of those activities with AppTheme
<style name="AppTheme.SearchActivity" parent="AppTheme">
...
</style>

Make toolbar and menu button have smaller height

I have a toolbar (please see xml below). Is there any easy way to make the tool bar thinner and keep the menu button.
Or maybe just have a menu button in some corner?
This started out as a full screen activity, but i roll up my own view and do a: setContentView(view);
thanks
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
</resources>
Specifying this styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionBarSize">20dp</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="actionButtonStyle">#style/MyActionButtonStyle</item>
<item name="displayOptions">homeAsUp</item>
</style>
<style name="MyActionButtonStyle" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:minWidth">20dp</item>
<item name="android:minHeight">20dp</item>
</style>
Will result in this output:

Activity not transparent while using Theme.AppCompat

I have tried lots of to make activity or main layout transparent using theme defined into style.xml with different different attribute in theme still not working.
Only view.setalpha(0) that makes layout or activity is transparent, but how to possible through style.xml. I am using Theme.AppCompact for support lower version of Android device.
Also i have tried lots of SO answer but none of one is working. What i am doing wrong or any correction there? what I have done so far is as following.
Please help me to solve the issue.
style.xml
<!-- 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>
<style name="Theme.AppCompat.Translucent" parent="AppTheme">
<item name="android:background">#android:color/transparent</item> <!-- Or any transparency or color you need -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demo.intel.com.serviceprogressbarnotification">
<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=".MainActivity"
android:theme="#style/Theme.AppCompat.Translucent">
</activity>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Well I have same case but I wanted to make my window to act like dialog and on the background of it I put my required transparency level. here is the style I used:
<style name="transparent_alertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimAmount">0.95</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowMinWidthMajor">50%</item>
<item name="android:windowMinWidthMinor">50%</item>
<item name="android:windowContentOverlay">#null</item>
<item
name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
and in manifest I used it like :
<activity
android:name=".PaymentConfirmationActivity"
android:label=""
android:theme="#style/transparent_alertDialog"
android:windowSoftInputMode="adjustPan"/>
So it did the trick for me.
Hope so it will help for you too.

colorprimarydark only work for the mainactivity,what should i do with it

this is my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<service android:name="com.amap.api.location.APSService" />
<activity
android:name=".MainActivity"
android:label=""/>
<activity
android:name=".QueryActivity"
android:label="" />
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegistActivity" />
<activity
android:name=".TaskListActivity"
android:label="" />
<activity
android:name=".TaskWatcherActivity"
android:label="" />
<activity
android:name=".DetailsActivity"
android:label="" />
</application>
i have set the style in style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#color/cpb_white</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
&style-v21:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:textSize">15sp</item>
<item name="android:colorControlNormal">#color/cpb_white</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
but only the mainactivity's status bar is in colorprimarydark,other activities' statusbar is in the color of their layout's background. so how can i make colorprimarydark work for every activity's status bar
Very easy and useful library for Tint Color use this library in every Activity set you status color.
Try to Use android:theme="#style/AppTheme" in each and every activity.
I think you solve your problem.
finally, i used the library for Tint Color to solve the problem, p.s.thasks to Jhaman Das.
And i found that the attr of statusBarColor would cover the effect of colorpromarydark, it is the drawlayout that can have the ideal effect. willing to get further discussion on this problem.

Categories

Resources