No se puede eliminar una vista adjunta por windowManager.addView ()
Estoy intentando eliminar una capa agregada a WindowManager. Pero nada sucede cuando llamo a removeView (). ¿Alguien sabe cómo eliminarlo? Mi código se ve así.
public class MainActivity extends Activity implements View.OnClickListener{ private WindowManager wm; private WindowManager.LayoutParams orientationLayout; private LinearLayout orientationChanger; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // init landscape things wm = (WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE); orientationChanger = new LinearLayout(getApplicationContext()); orientationChanger.setClickable(false); orientationChanger.setFocusable(false); orientationChanger.setFocusableInTouchMode(false); orientationChanger.setLongClickable(false); orientationLayout = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.RGBA_8888); orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // set view setContentView(R.layout.calibrate); findViewById(android.R.id.button).setOnClickListener(this); lockLandScape(); } public void lockLandScape(){ wm.addView(orientationChanger, orientationLayout); orientationChanger.setVisibility(View.GONE); orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; wm.updateViewLayout(orientationChanger, orientationLayout); orientationChanger.setVisibility(View.VISIBLE); } public void releaseLandScape(){ wm.removeView(orientationChanger); // This doesn't work as well //wm.removeViewImmediate(orientationChanger); } @Overrride public void onClick(View view){ Log.i("myapp", "clicked") releaseLandScape(); } }
- Android Crash, java.lang.IllegalArgumentException: El tipo de ventana no se puede cambiar después de agregar la ventana
- ¿Es posible mostrar siempre la barra de acción cuando se utiliza adjustPan como modo de entrada suave?
- Mostrar una vista utilizando el gestor de ventanas en la pantalla de bloqueo
- No se puede eliminar la vista de superposición
- Caught a RuntimeException de la implementación de stub de enlace cuando intercambia datos en arrayadapter
- Android.view.WindowManager $ BadTokenException
- Combinación WindowManager.LayoutParams que puede pasar eventos a capas bajo TYPE_SYSTEM_ALERT o smilar
- Programáticamente set android: windowIsTranslucent
- ¿Qué es WindowManager en android?
- Adición de la vista seleccionable al gestor de ventanas sin perder la respuesta en el fondo
- ¿Por qué algunas veces la aplicación se reinicia en killProcess?
- Obtener la visualización de la ventana desde el servicio de Android
- FLAG_TURN_SCREEN_ON no funciona
En lugar de usar un atributo como wm, ¿podría intentar usar
(WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)
cada vez ?
me gusta :
((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(orientationChanger);
- ¿Es una buena idea inicializar Crashlytics, en el método onCreate de android?
- ¿Las aplicaciones móviles de cromo funcionan en cromo?