我想通過修改默認Toast來自定義我的烤麪包而不創建自定義佈局。我想要烤麪包的背景爲紅色,烤麪包的文字顏色爲白色,我想讓烤麪包的背景更大,以表示默認吐司。當我運行我的應用程序時,我的敬酒沒有任何變化,它仍然顯示默認烤麪包。如何自定義android中Toast的背景,背景顏色和文本顏色
這是我如何自定義我舉杯:
if (seriesSelection == null) {
Toast toast = Toast.makeText(getApplicationContext(), "tidak ada chart yang dipilih", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 50, 50);
toast.getView().setPadding(10, 10, 10, 10);
toast.getView().setBackgroundColor(Color.RED);
TextView text = (TextView) toast.getView().findViewById(android.R.id.message);
text.setTextColor(Color.WHITE);
text.setTextSize(14);
} else {
Toast toast= Toast.makeText(
getApplicationContext(),
"Nilai " + listData.get(seriesSelection.getPointIndex()).getInuNilai()+
" tanggal " + listData.get(seriesSelection.getPointIndex()).getTanggal(),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 50, 50);
toast.getView().setPadding(10, 10, 10, 10);
toast.getView().setBackgroundColor(Color.RED);
text.setTextColor(Color.WHITE);
text.setTextSize(14);
toast.show();
}
對我來說,'其他'案例顯示紅色烤麪包與白色文本與應用填充。 – sandrstar