我想我已经阅读了与此相关的所有问题,但仍未找到解决这一简单需求的良好解决方案......
我创建了几个自定义RelativeLayouts并以编程方式将它们添加到我的窗口。他们工作得很好,除了他们没有覆盖状态栏。当我想展示其中一个时,我试图隐藏状态栏,但当然隐藏的是我想要避免的动画。
注意:我在下面的示例中尝试使用" WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY而不是TYPE_PHONE。那个 覆盖状态栏,但它不接受我需要的触摸事件。
感谢您的任何建议!
这是我的自定义RelativeLayout:
public class MyView extends RelativeLayout {
public MyView(Context context) {
super(context);
init(context, null, 0);
}
public MyView(Context context, AttributeSet attrs) {
super(context,attrs);
init(context, attrs, 0);
}
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle)
{
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this, true);
this.setVisibility(View.GONE);
WindowManager windowManager = (WindowManager) activity.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(this, params);
}
....
这是我的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:background="#000000"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true">
<ImageView
android:id="@+id/myImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
/>
</RelativeLayout>
答案 0 :(得分:0)
以全屏模式运行视图。
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
如果是AppCompatActivity,请使用此功能。
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
答案 1 :(得分:0)
我试图在没有动画的情况下显示现有活动的全屏幕活动,甚至可以隐藏操作栏的隐藏动画。它也有点滞后。
我回到上面根据我的问题创建自定义RelativeLayouts,然后根据需要显示它们。 (在我想要显示RelativeLayout之前,我只需要隐藏操作栏一秒钟。)