代码之家  ›  专栏  ›  技术社区  ›  LizG

更改通知的位置

  •  0
  • LizG  · 技术社区  · 7 年前

    我在不同的设备上有两个应用程序-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) {}
            });
    }
    

    骑手应用程序 在屏幕中间,更改颜色和背景色。

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

    1 回复  |  直到 7 年前
        1
  •  1
  •   Prashanth Verma    7 年前

    试试这个。添加如下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();
    

    <?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>
    
    推荐文章