android - Full screen activity in landscape mode at the same time with configChanges -
in activity, have imageview moves (100, 100) coordinates clicking on it. added following code before setcontentview() in activity have full screen view in landscape mode:
if (getresources().getconfiguration().orientation == configuration.orientation_landscape) { getwindow().addflags(windowmanager.layoutparams.flag_fullscreen); } else { getwindow().clearflags(windowmanager.layoutparams.flag_fullscreen); }
everything works fine , when turn device landscape mode, have fullscreen view. need activity doesn't recreate turning landscape mode. example, if clicked on imageview , moved (100, 100), after going landscape mode should stay on coordinates. this, added line manifest:
android:configchanges="orientation|screensize"
but adding line manifest, fullscreen property stops working.
can me have these 2 property simultaneous please?
in advance , sorry bad english.
activity :
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getresources().getconfiguration().orientation == configuration.orientation_landscape) { getwindow().addflags(windowmanager.layoutparams.flag_fullscreen); } else { getwindow().clearflags(windowmanager.layoutparams.flag_fullscreen); } setcontentview(r.layout.activity_main); final imageview imageview = (imageview)findviewbyid(r.id.imageview); imageview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { imageview.setx(100); imageview.sety(100); } }); }
}
xml :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <imageview android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/imageview" android:background="#000000"/> </linearlayout>
manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test"> <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:configchanges="orientation|screensize"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application>
as edson menegatt said, add following code @ end of activity, , problem solved:
@override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); // checks orientation of screen if (newconfig.orientation == configuration.orientation_landscape) { getwindow().addflags(windowmanager.layoutparams.flag_fullscreen); } else if (newconfig.orientation == configuration.orientation_portrait){ getwindow().clearflags(windowmanager.layoutparams.flag_fullscreen); } }
the codes before setcontentview() wrote in question, necessary too.
thank edson menegatti ...
Comments
Post a Comment