How can I get a light blue halo of toast in my regular toast?

I create my own toast mainly because I put it on the grid and need some control over its width. But I really like the light blue halo on the standard toast and would like to bring it back (or at least my custom toast looks a bit like the default toast).

What is a simple / elegant way to achieve this?

I created a custom toast from this layout:

<LinearLayout android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:padding="10dp"> <ImageView android:id="@+id/toast_layout_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_marginRight="10dp"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toast_layout_text" android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> </TextView> </LinearLayout> 

and refer to it this way (the general approach described in the documentation for Android, as well as several tutorials on the Internet, the only difference is that I work with a grid view, and each toast is placed in accordance with its grid position):

 int location[] = new int[2]; view.getLocationOnScreen(location); LayoutInflater inflater = getLayoutInflater(); View toastLayout = inflater.inflate(R.layout.toast_layout,(ViewGroup)findViewById(R.id.toast_layout_root)); TextView textView = (TextView) toastLayout.findViewById(R.id.toast_layout_text); textView.setText("This tile does not contain any valid data."); int toastWidth = cellWidth * 3 / 4; textView.setWidth(toastWidth - 64); // TODO picture size needs to be correct Toast toast = new Toast(getApplicationContext()); toast.setView(toastLayout); toast.setDuration(Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP|Gravity.LEFT, location[0]+((cellWidth-toastWidth)/2),location[1]+cellHeight-100); toast.show(); 

It looks very clean, but completely different from the default toast.

+4
source share
1 answer

apply this layout for a message with a toast:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="35dp" android:orientation="horizontal" android:background="@android:drawable/dialog_holo_dark_frame" > <ImageView android:id="@+id/toast_layout_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/appicon" android:layout_marginRight="10dp"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toast_layout_text" android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> </TextView> </LinearLayout> 

I did not find what cellWidth and cellHeight are, so try experimenting with the add-on if it doesn't fit.
Edit: Oh, I applied a dark theme, try using light instead.

+4
source

Source: https://habr.com/ru/post/1383390/


All Articles