Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 改变土司的颜色_Android - Fatal编程技术网

Android 改变土司的颜色

Android 改变土司的颜色,android,Android,如何更改邮件的颜色 这是我的代码: public void checkButton(View view) { if(count < 0){ Toast.makeText(getApplicationContext(), "Incorreto!", Toast.LENGTH_SHORT).show(); } else if(count == 0){ Toast.makeText(getApplic

如何更改邮件的颜色

这是我的代码:

 public void checkButton(View view) {


    if(count < 0){
        Toast.makeText(getApplicationContext(), "Incorreto!",
                Toast.LENGTH_SHORT).show();
    }

    else if(count == 0){
        Toast.makeText(getApplicationContext(), "Correto",
                Toast.LENGTH_SHORT).show();
        }

    }
}
公共作废检查按钮(视图){
如果(计数<0){
Toast.makeText(getApplicationContext(),“Incorreto!”,
吐司。长度(短)。show();
}
否则如果(计数==0){
Toast.makeText(getApplicationContext(),“Correto”,
吐司。长度(短)。show();
}
}
}

创建自定义Toast布局,例如
correct_Toast.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/toast_layout_root"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="8dp"
          android:background="#DAAA">
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#FFF"
              />
</LinearLayout>

这样,您就可以更改背景颜色和/或文本颜色。

更改土司颜色、位置和背景颜色的方法是:

    Toast toast=Toast.makeText(getApplicationContext(),"This is advanced toast",Toast.LENGTH_LONG);
    toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT,0,0);
    View view=toast.getView();
    TextView  view1=(TextView)view.findViewById(android.R.id.message);
    view1.setTextColor(Color.YELLOW);
    view.setBackgroundResource(R.color.colorPrimary);
    toast.show();

逐行解释:

或使用自己的版式敬酒。Bogdan Ustyak!非常感谢你!这在Android 11及更高版本中不再可能
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.correct_toast,
                           (ViewGroup) findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
    Toast toast=Toast.makeText(getApplicationContext(),"This is advanced toast",Toast.LENGTH_LONG);
    toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT,0,0);
    View view=toast.getView();
    TextView  view1=(TextView)view.findViewById(android.R.id.message);
    view1.setTextColor(Color.YELLOW);
    view.setBackgroundResource(R.color.colorPrimary);
    toast.show();