我想改变下toast的背景和文本颜色
用了下面的方法:
LayoutInflater
infator = getLayoutInflater(); View
layout =infator.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout)); TextView
toastText = (TextView) findViewById(R.id.toasttext); toastText.setBackgroundColor(Color.YELLOW); toastText.setText("uei:"+o.getUei()); Toast
toast = newToast(getApplicationContext());toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show();
这个代码是我的listview的OnItemClickListener的,但是app由于空指针异常被强制关闭了
这是onclick listener上面的代码:
publicvoid
onCreate(finalBundle
savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alarms); m_alarmAdapter
= newAlarmAdapter(this,
R.layout.severity_item, m_alarms); setListAdapter(m_alarmAdapter); ListView
lv = getListView(); lv.setOnItemClickListener(newOnItemClickListener()
{ publicvoid
onItemClick(finalAdapterView<?>
parent, finalView
view, finalint
position, finallong
id) { Log.d(TAG,"clicked:
"
+ view); finalAlarm
o = m_alarmAdapter.getItem(position); LayoutInflater
infator = getLayoutInflater();
本文介绍了一种在Android应用中自定义Toast消息样式的方法,包括如何更改背景和文本颜色。通过LayoutInflater加载自定义布局并设置TextView的颜色及内容。
1291

被折叠的 条评论
为什么被折叠?



