0
我有RelativeLayout,我想在窗口中顯示。 我做這樣的方式:WindowManager只顯示背景
static WindowManager wManager;
WindowManager.LayoutParams params = new WindowManager.LayoutParams(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN, android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN, android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT);
wManager = (WindowManager) activity_home.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) activity_home.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.order_wait, null);
wManager.addView(view, params);
但我只看到RelativeLayout的背景,並沒有看到它的內容。
order_wait.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:orientation="vertical"
>
<LinearLayout
android:id="@+id/ll_oder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/gray_without_corners"
android:orientation="vertical"
android:layout_marginTop="80dp"
>
<FrameLayout
android:id="@+id/fr_poisk"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/txt_poisk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Автомобиль будет через:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
<TextView
android:id="@+id/txt_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0:30"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#111111"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_bot"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#B6B6B6" >
<Button
android:id="@+id/bt_cancel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/but_yellow"
android:text="ОТМЕНА"
android:textColor="#1e90ff"
android:textSize="20dp" />
</LinearLayout>
</RelativeLayout>
感謝您的答案。
我該怎麼做? WindowManager沒有獲取ViewGroup的方法。 – Artem
嗨,我已經添加android.permission.SYSTEM_ALERT_WINDOW清單,我可以看到你的原代碼正在運行。請嘗試添加此權限並查看。 – Sheshu
我有此權限。不起作用。 Thahk你 – Artem