私はサービスからチャットヘッドを表示できるアプリのようなFacebook Messanger Chatの頭を作ろうとしています。私はそれらのすべてが使用する例の束を読むWindowManager.LayoutParams.TYPE_SYSTEM_ALERT
。しかし、問題はそれが他のすべてのアプリへの入力をブロックするので、ユーザーは画面を開いたり、アプリを開いたりすることができなくなります。WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
を使用しようとすると、チャットヘッドが表示され、画面を自由にナビゲートできます。チャットヘッドはonClick
のような入力を受け取りません。TYPE_SYSTEM_ALERTは他のアプリへの入力を妨害しています〜Android
私の質問は、他のアプリへの入力をブロックしないようにチャットヘッドを作る方法で、onClick
やonTouch
などの入力を受け取ることができます。
私は、サービスののonCreate内のビューを作成する方法をHERESに:
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
view = LayoutInflater.from(this).inflate(R.layout.chat_popup, null);
相続人は私がサービスからビューを表示する方法:
private void showBubble() {
try {
mWindowManager.removeView(view);
} catch (Exception ignore) {
ignore.printStackTrace();
} finally {
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(view, params);
trashView.setVisibility(View.GONE);
isViewAdded = true;
}
}
そしてHERESに私のチャットヘッドのレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/profile_imageview"
android:layout_marginBottom="5dp"
android:layout_marginEnd="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:elevation="20dp"
android:minHeight="50dp"
android:minWidth="50dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="25dp">
<TextView
android:id="@+id/text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:gravity="start"
android:maxLines="5"
android:paddingBottom="5dp"
android:paddingEnd="15dp"
android:paddingStart="55dp"
android:paddingTop="5dp"
android:scrollbars="vertical"
android:textColor="@color/white"
android:textSize="16sp" />
</android.support.v7.widget.CardView>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_imageview"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
android:elevation="50dp"
android:src="@drawable/thumbnail" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/trash_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:cardBackgroundColor="@color/transparentBlack"
app:cardCornerRadius="30dp">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:padding="8dp"
android:src="@drawable/ic_close_white_24dp" />
</android.support.v7.widget.CardView>
</RelativeLayout>
私は解決策があることを知っていますが、今私は立ち往生しており、私は運がない解決策を探していました。
誰でも手助けできますか?
ありがとうございます。
ええ、MATCH_PARENTは問題のようです。ありがとう、今それは動作します。 –