Andriod: Navigation bar hides, but activity is not fill screen - android

Trying to create simple application with fullscreen video playing.
Navigation bar hides, but activity is not filling the screen.
What am I missing?
activity:
<FrameLayout 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="my.test.app2.VViewer">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout >
public class VViewer extends AppCompatActivity {
private VideoView myVideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vviewer);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
);
}
#Override
protected void onResume ()
{
super.onResume();
myVideo=(VideoView)findViewById(R.id.videoView);
myVideo.setVideoPath(MP4FileName);
myVideo.start();
}
theme for activity
<style name="AppTheme.FullscreenTheme" 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>

you can try this :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

My code works fine for 16:9 screen devices. Problems only on 18:9 devices.
I don't understand why, but adding
<meta-data android:name="android.max_aspect" android:value="2.1" />
to application section of android manifest file solves the problem.

Related

Android:Status bar color changes when searchview is triggered

I am implementing searchview in my app. When I click on search new activity is opened to show results but the color of status bar changes in new activity. Here is my code:
activity_search.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/search_results_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
SearchResultActiviy.java
public class SearchResultActivity extends AppCompatActivity{
private Toolbar toolbar;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
toolbar = (Toolbar) findViewById(R.id.toolbar);
handleIntent(getIntent());
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
query = intent.getStringExtra(SearchManager.QUERY);
getPatientList(startRow,pageSize);
}
}
AndroidManifest.xml
<activity android:name=".activities.SearchResultActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
Style.xml
<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>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textAllCaps">false</item>
</style>
here are the images
In your Style.xml, you define the statusBarColor to transparent.
This parameter need API level 21.
I recommend deleting the line :
<item name="android:statusBarColor">#android:color/transparent</item>
The color of status bar is set by ColorPrimaryDark (see https://developer.android.com/training/material/theme.html)
If you want to change the color dynamically, use
Window window = activity.getWindow();
// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));
Explain in this thread : statusBar
(It's my first answer, hope it helps)

App name showing on top of Alert Activity popup

Im showing a popup alert activity, when select a notification from tray.
But on top it's showing the App name (MCP), with improper alignment.
I don't want the top part, just a normal dialog.
Manifest:
<activity
android:name=".activity.AlertDialogActivity"
android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
android:excludeFromRecents="true"
android:theme="#style/AlertDialogTheme" />
Style:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Alert activity:
public class AlertDialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog);
this.setFinishOnTouchOutside(false);
String message = getIntent().getExtras().getString("message");
TextView tvPushMessage = (TextView) findViewById(R.id.tvAlertMessage);
tvPushMessage.setText(message);
Button btnPushOk = (Button) findViewById(R.id.btnAlertOk);
btnPushOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/background_round_rectangle"
android:padding="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/tvAlertMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black" />;
<Button
android:id="#+id/btnAlertOk"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#id/tvAlertMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/btn_use"
android:text="#string/ok"
android:textColor="#color/white" />
</RelativeLayout>`
Also tried:
requestWindowFeature(Window.FEATURE_NO_TITLE);
and:
getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)
before setContentView()
Just Add Following code in style.xml
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
or You can hide it Programmatically.
getSupportActionBar().hide();
Try this code (without using "android:")
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I used this:
In AppCompatActivity onCreate() add following code:
setTitle("")
and Add The following code in style.xml
<style name="PopupWindowTheme" parent="#style/Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">#style/AnimBottom</item>
</style>
Add requestWindowFeature in this way may be work proper.
First Call Super after add it.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add__favourite_layout);
}

How to prevent the actionMode and toolbar to "jump" when toggling between them?

Background
I have an activity in my app that has a toolbar as the actionBar, and it also has an actionMode, for multi-selection of items.
The problem
Every time I close the actionMode, there is a "jump" between the two modes, so I can see both the toolbar and the actionMode.
Maybe I'm just doing it wrong, but I remember it worked fine in the past.
Here's how it looks like using the snippet code I've made:
What I've tried
This is a snippet of the code I've used. To test it, run the app, wait a moment for the actionMode to appear, and then either press the back button, or press the button on the actionMode. Do note that all classes that I use are of the support library (when available).
MainActivity.java
public class MainActivity extends AppCompatActivity {
protected ActionMode.Callback _actionModeCallback;
protected ActionMode _actionMode;
Toolbar _toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_toolbar = (Toolbar) findViewById(R.id.activity_app_list__toolbar);
setSupportActionBar(_toolbar);
_actionModeCallback = new ActionMode.Callback() {
#Override
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
return false;
}
#Override
public void onDestroyActionMode(final ActionMode mode) {
_toolbar.setVisibility(View.VISIBLE);
_actionMode = null;
}
#Override
public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
_toolbar.setVisibility(View.GONE);
return true;
}
#Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
mode.finish();
return true;
}
};
//
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
_actionMode = startSupportActionMode(_actionModeCallback);
}
}, 2000);
}
}
activity_main.xml
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/activity_app_list__toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:colorControlNormal="?attr/colorControlNormal"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
tools:ignore="UnusedAttribute"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"/>
</FrameLayout>
</LinearLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#FF0288D1</item>
</style>
</resources>
The question
Why is this happenning? How can I fix it?
Is this a known bug, perhaps?
What you're looking for is the ACTION_MODE_OVERLAY flag. In your Activity.onCreate() method, add the following before the call to super.onCreate():
#Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
super.onCreate(savedInstanceState);
// other stuff...
}
The same as described by #Kevin Coppock can also be achieved by adding <item name="windowActionModeOverlay">true</item> in your AppTheme.
The theme could look like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#FF0288D1</item>
<item name="windowActionModeOverlay">true</item>
</style>

How to create custom window title on preference activity android?

When building an application, sometimes we need to create a custom window title to suit our needs and make our application differs from others. I've problem on create icon window title on preference activity by this code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
addPreferencesFromResource(R.layout.setting);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.setting);
}
Can anybody help me?
public class Preferences extends PreferenceActivity {
protected ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main_tab);
title = (TextView) findViewById(R.id.img);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
int width=30;
int height=20;
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
this.img.setImageBitmap(resizedbitmap);
}
}
///////In title_bar.xml///////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="3dp">
</ImageView>
</RelativeLayout>
Try:
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.drawable.icon);
try this
Create custom layout for window title in “layout” folder.
window_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="#+id/header"
android:src="#drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Create custom style in “values” folder.
custom_style.xml
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
Apply custom style in manifest file as theme.
AndroidManifest.xml
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/CustomTheme">
4.Apply custom window title in main activity class
CustomWindowTitle
public class CustomWindowTitle extends PreferenceActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.Your_Custom_Title);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.YourPrf);
}
}
You can change icon and title of your preference activity in your Manifest file:
<activity
android:name="PATH TO YOUR ACTIVITY"
android:label="#string/title_from_resources"
android:icon="#drawable/icon_from_resources" >
</activity>

[Splash Screen]How to show an image in full screen?

I want to make a splash screen in my application, for that i need to know how to show an image in full screen. This could me made by XML or Java code ? And how?
For now i just made this:
public class SplashScreen extends Activity {
private static final int STOPSPLASH = 0;
private static final long SPLASHTIME = 5000;
private Handler splashHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
//remove SplashScreen from view
Intent intent = new Intent(SplashScreen.this, jetpack.class);
startActivity(intent);
break;
}
super.handleMessage(msg);
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Message msg = new Message();
msg.what = STOPSPLASH;
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}
}
How can be this splash_screen.xml ?
Thank you for your help.
The best way to show a full screen splash activity is by putting this line in your manifest under activity tag
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen"
You can use other themes as well
Theme.Black.NoTitleBar.Fullscreen
Theme.NoTitleBar.Fullscreen
<activity
android:name="com.example.SplashActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For Latest Api Lollipop and above
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Define this theme for the splash activity and provide it in manifest
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/image" />
</LinearLayout>
and add the below code before setContentView(R.layout.splash_screen);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
If R.layout.splash_screen included an image with height and width set to fill_parent or match_parent (depending on version). It will fill the screen
<style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
just using super.onCreate and setConntentView
code :
/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);

Categories

Resources