更改通知的位置

时间:2018-08-30 18:42:24

标签: android notifications position toast

我在不同设备上有两个应用程序-Rider&Driver。驾驶员接受请求后,我将从驾驶员应用程序向驾驶员应用程序发送通知:

private void acceptBooking(String customerId) {

    Token token = new Token(customerId);

    Map<String, String> content = new HashMap<>();
    content.put("title", "Accept");
    content.put("message", "Your request is accepted, Please make your payment!");


    DataMessage dataMessage = new DataMessage(token.getToken(), content);

    mFCMService.sendMessage(dataMessage)
        .enqueue(new Callback<FCMResponse>() {
            @Override
            public void onResponse(Call<FCMResponse> call, Response<FCMResponse> response) {
                if (response.body().success == 1) {
                    Toast.makeText(CustomerCall.this, "Ride Accepted",
                            Toast.LENGTH_SHORT).show();
                    finish();
                }
            }

            @Override
            public void onFailure(Call<FCMResponse> call, Throwable t) {}
        });
}

运行acceptBooking()后,驱动程序会收到一个吐司“ Ride Accepted”,而车手会收到一个吐司“您的请求已接受,请付款!”

我需要做的是将烤面包放在屏幕中间的 Rider App 中,更改颜色和背景色。

我尝试了以下建议,但似乎不适用于此类通知。

1 个答案:

答案 0 :(得分:1)

尝试一下。添加这样的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/custom_toast_container"
android:background="@drawable/complete_round_light_green_fill">

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginHorizontal="24dp"
    android:layout_marginVertical="15dp"
    android:layout_gravity="center_horizontal"
    android:fontFamily="@font/ubuntu"
    android:textSize="14sp"
    android:lineSpacingExtra="7sp"
    android:textColor="@color/white"
    tools:text="abcd"
    />

</LinearLayout>

在Java代码中添加此代码。如您所见,我们可以添加背景,将重力设置为吐司:

LayoutInflater inflater = LayoutInflater.from(this);
    View layout = inflater.inflate(R.layout.layout_toast_green, null);

    LinearLayout customContainer = (LinearLayout) layout.findViewById(R.id.custom_toast_container);
    customContainer.setBackgroundResource(R.drawable.complete_round_mgred_fill);
    TextView text = (TextView) layout.findViewById(R.id.message);
    text.setText("Your request is accepted, Please make your payment!");

    Toast toast = new Toast(AppController.getContext());
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER,0,0);
    toast.setView(layout);
    toast.show();

complete_round_light_green_fill的Xml代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape android:shape="rectangle" >
        <solid android:color="#78cd96" />
        <corners android:radius="100dip"/>
    </shape>

</item>

</layer-list>