怎样才能在我的自定义祝酒词中得到浅蓝色的光环呢?



我创建我的自定义吐司主要是因为我把它放在一个网格视图,需要一些控制它的宽度。但是我真的很喜欢标准吐司上的浅蓝色光环,并希望恢复它(或者至少让我的自定义吐司看起来与默认吐司有点相似)。

有什么简单/优雅的方法可以做到这一点?

我从这个布局创建了一个自定义toast:

    <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>

并以这种方式调用它(在android dev.文档中概述的常见方法以及web上的几个教程,唯一的区别是我使用网格视图,每个toast根据其网格平铺位置放置):

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();

这看起来很干净,但完全不同于默认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>

我没有找到什么是cellWidth和cellHeight,所以尝试尝试填充,如果它不适合
编辑:哦,我应用了暗主题,试着用光代替。

最新更新