如何解决我正在使用此代码在android 11及更低版本的android 11中设置灯光状态栏,但不赞成弃用警告
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Info {
private String account;
private String opportunity;
private Integer value;
private String desc;
private Info(String account,String opportunity,Integer value,String desc) {
super();
this.account = account;
this.opportunity = opportunity;
this.value = value;
this.desc = desc;
}
public static void main(String[] args) {
List<Info> infos = new ArrayList<>();
infos.add(new Info("12","absddd",4,"production"));
infos.add(new Info("1234","abss",10,"vip"));
infos.add(new Info("1234","abs","test"));
infos.add(new Info("1234",5,"testing"));
infos.add(new Info("123",8,"vip"));
infos.add(new Info("12","absooo",2,"test"));
Map<String,Map<String,List<Info>>> sortedResult = infos.stream().sorted(Info::compareByValueDesc)
.collect(Collectors.groupingBy(Info::getAccount,LinkedHashMap::new,Collectors.groupingBy(r -> r.getopportunity(),Collectors.toList())));
sortedResult.forEach((key,value) -> System.out.println(key + value.toString()));
}
public static int compareByValueDesc(Info other1,Info other2) {
return -other1.value.compareto(other2.value);
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getopportunity() {
return opportunity;
}
public void setopportunity(String opportunity) {
this.opportunity = opportunity;
}
public String toString() {
return this.value.toString();
}
}
我正在使用此代码在android 11及更低版本的android 11中设置灯光状态栏。一切正常,只是有一个小问题,弃用警告不起作用。
解决方法
不赞成使用警告-您有正确的if
声明,导致在< 30
上使用尚未弃用的方法,在30+
上使用了新方法
我只是做了一件事,因为我的if语句很好,所以我只是通过使用禁止了警告 @SuppressWarnings(“弃用”)
我只是将此注释用于包含此代码的特定方法。
存在另一个也很好的选项: 只需添加
//noinspection deprecation
已弃用的代码行以上。这将允许检查整个功能中的其他警告。哪个很好,我会更喜欢。
与@SuppressWarnings(“ deprecation”)相比,//无检查弃用有什么优势?
这可以防止@SupressWarnings出现问题,因为它会忽略方法中的所有警告。因此,如果您不知道某些已弃用的内容,@ SupressWarnings会将其隐藏,并且不会收到警告。这就是// noinspection
的优势测试并检查此帖子中的更多详细信息答案: How to suppress specific Lint warning for deprecated Android function?
,if(fullScreen)
{
getWindow().getDecorView().getWindowInsetsController().hide(WindowInsets.Type.statusBars());
getWindow().getDecorView().getWindowInsetsController().setSystemBarsBehavior(BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
else
{
getWindow().getDecorView().getWindowInsetsController().show(WindowInsets.Type.statusBars());
getWindow().getDecorView().getWindowInsetsController().setSystemBarsBehavior(BEHAVIOR_SHOW_BARS_BY_SWIPE);
}
以上代码用于从 Android 11 开始全屏显示,设置 setSystemBarsBehavior(BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) 很重要,否则在向下滑动状态栏时会显示并且在不重新创建活动之前不会消失。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。