I have an activity. It does not have a title bar. The content view is just a linear layout. It looks like android draws a drop shadow at the top of my content view, directly below the status bar. Is there a way to stop that from being drawn?
My layout is just:
<LinearLayout ... />
I have no titlebar:
requestWindowFeature(Window.FEATURE_NO_TITLE);
Thanks.
In res/values/styles.xml:
<style name="Theme.Custom" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
</style>
Then in your manifest:
<activity android:name=".YourActivity"
android:theme="#style/Theme.Custom" >
...
</activity>
In res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
</style>
</resources>
Related
What's wrong with AppCompat?
My application does not use AppCompat and there are no problems with XML Layout
But after I use AppCompat why is the XML Layout not full on the screen?
I tried by creating a new XML layout, but the results were the same.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello World!"/>
</LinearLayout>
Add this theme to your activity
in style.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
and define this style to your activity in AndroidManifest :
<activity
android:name=".YourActivity"
android:theme="#style/AppTheme"/>
Using this will remove the extra space coming for toolbar by default.
You can achieve fullscreen mode when you use AppCompact like this
Add this to your style file
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen"
parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
And in your manifest file add this to your Activity tag
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
If I apply theme for whole application it hides ActionBar title successfully:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>
assign in manifest:
<application
android:name="myapp"
android:allowBackup="true"
android:icon="#drawable/action_bar_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
I need ActionBar title hidden just in one activity.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
...other things...
</style>
<style name="MainActivityTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
</resources>
setting this theme explicitly for one activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/mainLayout"
android:orientation="vertical"
android:theme="#style/MainActivityTheme">
and it still shows title in MainActivity ActionBar. I know how to hide the title in java, I need to know what I do wrong here in XML.
Set the theme on your activity in the manifest.
<activity
android:name=".MyActivity"
android:theme="#style/MainActivityTheme" />
You probably want to create a sub-theme which hides the action bar:
<style name="AppTheme.NoActionBar">
<item name="android:windowActionBar">false</item>
</style>
and then apply it to your activity in the manifest like so:
<activity android:name="NonActionBarActivity"
android:theme="#style/AppTheme.NoActionBar" />
Using the dot notation (AppTheme.NoActionBar) makes this NoActionBar theme inherit everything from AppTheme and override the setting on android:windowActionBar. If you prefer you can explicitly note the parent:
<style name="AppThemeWithoutActionBar" parent="AppTheme">
<item name="android:windowActionBar">false</item>
</style>
Also, if you're using the AppCompat libraries, you probably want to add a namespace-less version to the sub-theme.
<item name="windowActionBar">false</item>
If you want to remove actionbar title then just remove label attribute from <activity> tag in your manifest file.
Such as,
<activity
android:name=".YourActivityName"
android:label="#string/title" />
And after removing,
<activity
android:name=".YourActivityName" />
Done!
How to create an app that has a floating view all over the others, and always stays at the top. Is it an open activity, If so how to crate a such view?
similat to how its done in the following app:
https://play.google.com/store/apps/details?id=genius.mohammad.floating.stickies&hl=en
You need a transparent activity.
Create a style.xml inside values folder:
<?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>
in manifest:
<activity android:name=".SampleActivity" android:theme="#style/Theme.Transparent">
...
</activity>
Use a FrameLayout to let those views float and overlap.
To change views on top. use bringToFront() method for view.
Those views can be LinearLayout that contains ImageView, TextViews and may also contain FrameLayouts. you can also get use of the background property for those controls.
what I want to achieve is activity with dialog-like transparency with 100% visibility of RelativeLayout content. This is activity's xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dip"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:layout_marginTop="50dip">
(...)
</RelativeLayout>
</LinearLayout>
and this is manifest:
<activity
android:name="com.acentic.rcontrol.activities.MyActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
</activity>
Right now background is still visible, what am I doing wrong?
--- EDIT:
I added
android:background="#c0000000"
to LinearLayout. Now background is transparent as I wanted to, but also TextViews inside RelativeLayout are also transparent.. how to change it?
Try to set
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
in your activity.
You can also try to do this in a style:
<style name="AppTheme" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
Create Style
<style name="MyTransparentTheme" parent="android:Theme.Dialog">
<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>
this is manifest:
<activity
android:name="your package.activity"
android:theme="#style/MyTransparentTheme">
</activity>
I added android:background="#c0000000" to LinearLayout. Now background
is transparent as I wanted to, but also TextViews inside
RelativeLayout are also transparent.. how to change it?
Add a solid background to your RelativeLayout element.
This way the RelativeLayout will have a solid background, and only the margins will be transparent.
If your activity needs to extends from AppCompatActivity, you can create a custom style for your activity
<style name="transparentActivity" parent="Theme.AppCompat.NoActionBar">
<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:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
And then change the default style of your activity in the Manifest
<activity android:name=".MyActivity"
android:theme="#style/transparentActivity"/>
Otherwise, if you do not need your activity to extend from AppCompatActivity, just change the theme of your activity in the manifest in this way.
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"/>
After setting LinearLayout transparency try to set it's child transparency to the value that you want.
This should make them have different transparency than LinearLayout. Try it.
Can someone please explain why this statement works perfectly well:
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo);
and the next statement does not deliver
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
This is what I have in the style's department:
<style
name="dialog">
<!-- title encapsulating main part (backgroud) of custom alertdialog -->
<item
name="android:windowFrame">#null</item>
<!-- turn off any drawable used to draw a frame on the window -->
<item
name="android:windowBackground">#null</item>
<!-- turn off any drawable used to draw a frame on the window -->
<item
name="android:windowIsFloating">true</item>
<!-- float the window so it does not fill the screen -->
<item
name="android:windowNoTitle">true</item>
<!-- remove the title bar we make our own-->
<item
name="android:windowContentOverlay">#null</item>
<!-- remove the shadow from under the title bar -->
</style>
Try using the code in onCreate of the fragment as
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
}
https://stackoverflow.com/a/24375599/2898715 it's also possible to omit the setStyle call altogether, and define the defulat style that DialogFragments will use throughout the whole app.
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<!-- makes all dialogs in your app use your dialog theme by default -->
<item name="alertDialogTheme">#style/DialogTheme</item>
<item name="android:alertDialogTheme">?alertDialogTheme</item>
<item name="dialogTheme">?alertDialogTheme</item>
<item name="android:dialogTheme">?alertDialogTheme</item>
</style>
<!-- define your dialog theme -->
<style name="DialogTheme" parent="Theme.AppCompat.DayNight.Dialog.MinWidth">
<item name="android:buttonStyle">#style/button_green</item>
<item name="android:textColorHint">#color/green</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
.....
<application android:theme="#style/AppTheme">
.....
</application>
</manifest>
Try setting a parent theme like
<style name="dialog" parent="#android:style/Theme.Dialog"> Your theme attributes </style>
Try doing so through programming like below:-
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
or can be declared in xml file as well.
Calling the bottomSheetDialogFragment from the activty:
var bottomFragment = ServiceOtpVerficationFragment()
bottomFragment.setStyle(BottomSheetDialogFragment.STYLE_NO_TITLE,R.style.BottomSheetTheme)
bottomFragment.show(supportFragmentManager,"TAG")
Add this in styles.xml
<style name="BottomSheetTheme" parent="Theme.Design.Light.BottomSheetDialog"> <item name="bottomSheetStyle">#style/BottomSheetStyle</item>
</style>
<style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#android:color/transparent</item>
And In the fragment add extension as `BottomSheetDialogFragment()` to fragment class using colon.```