Today I started trying to optimize my application for landscape mode. But I just cannot get my application to run in landscape mode, there are no settings that I have enabled to force portrait.
I am showing my placeholder screen as an example.
I also double checked that auto rotate in my AVD is enabled. I have this problem on every AVD.
Declared like this in my manifest.
<activity
android:name=".PlaceholderActivity"
android:theme="#style/AppTheme.NoActionBar" />
My layout looks like this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_material_light"
android:orientation="vertical"
android:animateLayoutChanges="true" >
<View
android:id="#+id/icon"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_centerInParent="true"
android:background="#drawable/feedyr_full" />
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:layout_centerHorizontal="true"
android:visibility="visible" />
<include
layout="#layout/helper_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/icon"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And my Theme looks like this.
<style name="AppTheme.NoActionBar" 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>
<item name="android:colorButtonNormal">#color/colorAccent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
There is also nothing is my class that's forcing portrait
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_placeholder);
config = FirebaseRemoteConfig.getInstance();
model = Model.getInstance();
....
What am I missing?
Try setting the activity orientation to sensor :
<activity
android:name=".PlaceholderActivity"
android:theme="#style/AppTheme.NoActionBar"
android:orientation="sensor"/>
in your AndroidManifest
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" />
and in MainActivity.java
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation== Configuration.ORIENTATION_PORTRAIT)
{
}
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
}
}
hope it`s help
Don't ask me why, but suddenly the landscape mode works. I pressed the screen rotation buttons on the right menu. When it went back in landscape it suddenly worked. Did this before so don't know why it suddenly started to work.
I did not change anything in my code, theme, manifest or layout...
Try to enable the emulator screen rotation mode to work.
Related
Using floating/translucent windows with Android PIP causes a 3 second delay plus scaling issues. I've put together a sample app to demo the problem. I'm thinking there is some combination of tags I am either using incorrectly or completely missing some tag or tags. I tried many different combinations and came up with a few combos to demo the problem. I'll add code portions to give you and idea of what I am doing. I'll add additional or full code as needed. I want to try and keep this question compact but it may become long as I add more of the sample app necessary for you to actually run the app on your development environment.
Here are the significant sections from styles.xml for the test app:
<!--== ERROR CASE #1=================================-->
<!-- Causes 3 second delay to get into PIP mode -->
<!-- Incorrect window scale during 3 second delay -->
<!-- Incorrect window size after PIP exit -->
<!--=================================================-->
<item name="android:windowIsFloating">true</item>
<!--=================================================-->
<!--== ERROR CASE #2=================================-->
<!-- Causes 3 second delay to get into PIP mode-->
<!-- Window is not transparent -->
<!--=================================================-->
<item name="android:windowIsTranslucent">true</item>
<!--=================================================-->
<!--== ERROR CASE #3=================================-->
<!-- Causes 3 second delay to get into PIP mode -->
<!-- Incorrect window scale during 3 second delay -->
<!-- Incorrect window scale after PIP exit -->
<!--=================================================-->
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<!--=================================================-->
The following image is the initial app screen (as expected):
.
Putting the app into PIP mode causes
this screen for three seconds (unexpected delay and bad scale):
.
After 3 seconds, PIP mode is enabled ( expected image )
Exiting PIP results in an unusable activity due to bad scaling:
I'll add additional code snippets as necessary. But for now, I'm
thinking styles.xml file is incorrect.
Here is styles:
<resources>
<style name="StyleJava42" parent="Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowFullscreen">false</item>
<!--== ERROR CASE #1=================================-->
<!-- Causes 3 second delay to get into PIP mode -->
<!-- Incorrect window scale during 3 second delay -->
<!-- Incorrect window size after PIP exit -->
<!--=================================================-->
<item name="android:windowIsFloating">true</item>
<!--=================================================-->
<!--== ERROR CASE #2=================================-->
<!-- Causes 3 second delay to get into PIP mode-->
<!-- Window is not transparent -->
<!--=================================================-->
<item name="android:windowIsTranslucent">true</item>
<!--=================================================-->
<!--== ERROR CASE #3=================================-->
<!-- Causes 3 second delay to get into PIP mode -->
<!-- Incorrect window scale during 3 second delay -->
<!-- Incorrect window scale after PIP exit -->
<!--=================================================-->
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<!--=================================================-->
</style>
</resources>
And here is the manifest:
<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/Theme.AppCompat"
>
<activity
android:theme="#style/StyleJava42"
android:name=".MainActivity"
android:supportsPictureInPicture="true"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Bottom line, I need a usable transparent window going in to and out of PIP mode that does not cause scaling problems.
EDIT:2019_08_20 - As requested, here is the activity code:
public class MainActivity extends Java42LifeCycleTrace { //AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
if (isInPictureInPictureMode()) {
setContentView(R.layout.activity_main_pip);
} else {
setContentView(R.layout.activity_main);
}
}
}
public void pip(View v) {
((Button) v).setText("WORKING");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
PictureInPictureParams.Builder pipBuilder = null;
pipBuilder = new PictureInPictureParams.Builder();
PictureInPictureParams parms = pipBuilder.build();
enterPictureInPictureMode(parms);
}
}
public void exit(View v) {
finish();
}
}
Here is layout activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity"
>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#android:drawable/btn_default"
android:onClick="pip"
android:text="Press for PIP"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button2"
app:layout_constraintVertical_bias="0.100000024" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#android:drawable/btn_default"
android:onClick="exit"
android:text="Press to Exit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.100000024" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is layout activity_main_pip.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/btn_default"
android:text="PIP Mode"
/>
</LinearLayout>
I have been attempting to create an Activity that is opaque which overlaps another activity that is being shown in the background.
This is my XML layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EmergencyActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#color/opaque_back">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/button"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
Manifest file:
<activity
android:name=".EmergencyActivity"
android:theme="#style/Theme.Transparent">
Style:
<style name="Theme.Transparent" parent="AppTheme">
<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>
Images of the screens:
https://imgur.com/cqfBlNM - first activity screen
https://imgur.com/NUjTAdj - screen of the activity that isn't being fully displayed
I solved it by changing from appCompactActivity to Activity in order to use another style which isn't supported by the AppCompactActivity.
I changed the manifest to:
<activity
android:name=".EmergencyActivity"
android:launchMode="singleInstance"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen">
Your question is not clear enough but if you want to make an activity display full screen try this inside the activity class :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
I'm facing weird drawing issue with scene transitions (running with Nexus 5x 6.0.1 platform)
I found out that <item name="android:windowBackground">#null</item> has some relation to the issue.
Anyone know why this happens and what can be possible places to check in order to fix this?
Here is my test project setup to reproduce the problem:
minSdkVersion 16 and targetSdkVersion 23 using:
com.android.support:appcompat-v7:23.3.0
AndroidManifest.xml
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".NextActivity"/>
</application>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#null</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View iv = findViewById(R.id.iv_test);
ViewCompat.setTransitionName(iv, "test");
findViewById(R.id.b_go).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,
android.support.v4.util.Pair.create(iv, "test")).toBundle();
startActivity(new Intent(MainActivity.this, NextActivity.class), bundle);
}
});
}
}
NextActivity.java
public class NextActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
final View iv = findViewById(R.id.iv_test);
ViewCompat.setTransitionName(iv, "test");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:background="#android:color/white"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.test.scenetransitions.MainActivity">
<ImageView
android:id="#+id/iv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_dialog_email"
android:tint="#color/colorAccent"/>
<Button
android:id="#+id/b_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#color/colorAccent"
android:padding="20dp"
android:text="GO"/>
</RelativeLayout>
activity_next.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:background="#android:color/white"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.test.scenetransitions.MainActivity">
<ImageView
android:id="#+id/iv_test"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:src="#android:drawable/ic_dialog_email"
android:tint="#color/colorAccent"/>
</RelativeLayout>
And here is screenshot took in proper time during the transition:
The issue is with <item name="android:windowBackground">#null</item> you should never ever use null for window background. Replace it with <item name="android:windowBackground">#android:color/transparent</item>
When you set it to null Android doesn't know what to draw and it could draw any garbage from GPU. So you should explicitly specify transparent background.
I copy pasted your code, but i didn't get any drawing issues. I mean when the second page opens up, the image is a bit blurry(pixelated) that's cause of the small size of the actual image(if that's the case just use a bigger image in the second activity). May be its your device. I tested this in Moto E2. For me the transition is smooth, no drawing issues what so ever.
The red frame should not have in my code, but after I updated my Android Studio, it is showed in all of my APPS. please click and see the picture.
How to delete the red frame from my code? And it could not find in its design/text. The blue frame's begin code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/activity_login_user_email_edt"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="35dp"
android:autoText="true"
android:hint="e-mail" />
The Answer Skynet posted is correct,but this is the programatical way
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Full Screen and remove toolbar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
That is the theme your activity is extending from. You change it in the styles.xml. Then you need to update this setting in the Manifest.
You need to add this to styles.xml:
<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>
Then in your AndroidManifest.xml for this Activity:
<activity
android:name=".YourActivity"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>
The above will work if you are extending from AppCompatActivity which should look like:
public class YourActivity extends AppCompatActivity{}
im trying to build a Popup for my Android App. It should be a Activity which doesn't use the whole screen, just 200dp on the right side of the screen and the rest should be transparent black.
A Picture of what it looks like / what i want to have: http://i.stack.imgur.com/6APy6.png
Java:
public class ActivitySettings extends BaseActivity implements View.OnTouchListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setFinishOnTouchOutside(true);
}
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
System.out.println("Klicked " + motionEvent.getAction());
// If we've received a touch notification that the user has touched
// outside the app, finish the activity.
if (MotionEvent.ACTION_OUTSIDE == motionEvent.getAction()) {
finish();
return true;
}
return false;
}
}
AndroidManifest:
<activity
android:name="com.cleverlize.substore.test.ActivitySettings"
android:label="#string/title_activity_settings"
android:theme="#style/Theme.Transparent">
</activity>
Style XML:
<style name="Theme.Transparent" parent="Theme.AppCompat.Light">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/itemPremium</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
So i just need the adjustment and the ActionBar... please Help :)
You can have acitivity without titlebar and actionbar in manifest with the theme as
<activity
android:name="com.demo.YourActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
and for layout
for transperancy your base layout background will be android:background="#android:color/transparent"
your container layout will be
design as per your requirement with android:layout_alignParentRight="true"
Go to Android manifest file-> search for the required activity-> include this:
<--android:theme="#android:style/Theme.Translucent"-->
in the activity tag like this:
<activity
android:name=".Services"
android:label="#string/title_activity_services"
android:theme="#android:style/Theme.Translucent" >
</activity>
Suppose your Activity layout is inside the LinearLayout, set the inner layout margin from left 200sp:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="200sp"
android:background="#FFFFFF"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text Display"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>