注:不需要快捷方式,如http://www.eoeandroid.com/forum.php?mod=viewthread&tid=542394&extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline
里面的三星手机测试失败,如果有谁能够纠正一下的话,非常感谢。
急求类似qq桌面未读消息提示效果(android)
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
你知我知皆知 2024-08-03 13:52关注以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
我提供一个简单的示例,如何在Android中使用
TextView显示未读消息数量。这个例子是基于TextView的setCompoundDrawablesRelativeWithIntrinsicBounds()方法来改变其外观的,你可以根据自己的需求调整样式。public class UnreadMessageCounter extends AppCompatActivity { TextView textView; int unreadCount; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_unread_message_counter); textView = findViewById(R.id.text_view_unread_count); unreadCount = 0; // 设置初始未读消息数为0 // 获取当前activity的主题资源ID int themeResourceId = R.style.Theme_AppCompat_Light_NoActionBar; // 将主题应用到应用程序 ThemeUtils.applyTheme(this, themeResourceId); // 创建一个监听器,当用户点击时更新未读消息数 textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 更新未读消息数 updateUnreadCount(); } }); } private void updateUnreadCount() { // 当前活动的主题资源ID int themeResourceId = R.style.Theme_AppCompat_Light_NoActionBar; // 将主题应用到应用程序 ThemeUtils.applyTheme(this, themeResourceId); // 计算出当前的未读消息数 unreadCount = countUnreadMessages(); // 更新TextView中的内容 textView.setText(String.valueOf(unreadCount)); } private int countUnreadMessages() { // 这里可以添加你的逻辑来计算未读消息数,例如从数据库获取数据 return 0; } }在这个示例中,我们首先创建了一个新的Activity类
UnreadMessageCounter,并在其中设置了OnClickListener以处理用户点击事件。然后我们在onClick方法中调用了一个updateUnreadCount方法来更新未读消息数,并将结果设置到textView中。请注意,你需要根据你的实际项目修改这段代码。特别是你可能需要使用SQLite或其他数据库来存储未读消息数。此外,如果你正在使用第三方库或框架,请确保这些库也支持
TextView的setCompoundDrawablesRelativeWithIntrinsicBounds()方法。解决 无用评论 打赏 举报