君落兮 2015-03-24 08:23 采纳率: 0%
浏览 1231

急求类似qq桌面未读消息提示效果(android)

注:不需要快捷方式,如http://www.eoeandroid.com/forum.php?mod=viewthread&tid=542394&extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline
里面的三星手机测试失败,如果有谁能够纠正一下的话,非常感谢。

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-03 13:52
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    我提供一个简单的示例,如何在Android中使用TextView显示未读消息数量。这个例子是基于TextViewsetCompoundDrawablesRelativeWithIntrinsicBounds()方法来改变其外观的,你可以根据自己的需求调整样式。

    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或其他数据库来存储未读消息数。此外,如果你正在使用第三方库或框架,请确保这些库也支持TextViewsetCompoundDrawablesRelativeWithIntrinsicBounds()方法。

    评论

报告相同问题?