1.QMUI——Github
Github:https://github.com/Tencent/QMUI_Android qmuidemo地址:https://github.com/Tencent/QMUI_Android/tree/master/qmuidemo
引入依赖
implementation ‘com.qmuiteam:qmui:2.0.0-alpha10’
设置主题
注意:主题最好设置上,不然有些属性找不到,或者用了效果出不来! 可以设置全局app主题,也可以设置activity主题。
基本使用(以弹窗QMUIPopups为例)
效果
Java代码
binding.tv1.setOnClickListener(v -> {
String[] listItems = new String[]{
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
"Change Skin",
};
List<String> data = new ArrayList<>();
Collections.addAll(data, listItems);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(requireActivity(), R.layout.simple_list_item, data);
QMUIPopups.listPopup(requireActivity(),
QMUIDisplayHelper.dp2px(requireActivity(), 250),
QMUIDisplayHelper.dp2px(requireActivity(), 300),
adapter,
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(requireActivity(), "test", Toast.LENGTH_SHORT).show();
}
})
.animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
.preferredDirection(QMUIPopup.DIRECTION_TOP)
.shadow(true)
.edgeProtection(QMUIDisplayHelper.dp2px(requireActivity(), 10))
.offsetYIfTop(QMUIDisplayHelper.dp2px(requireActivity(), 5))
.skinManager(QMUISkinManager.defaultInstance(requireActivity()))
.show(binding.tv2);
});
simple_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="?attr/qmui_content_padding_horizontal"
android:paddingRight="?attr/qmui_content_padding_horizontal"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:background="?attr/qmui_skin_support_s_list_item_bg_1"
app:qmui_skin_background="?attr/qmui_skin_support_s_list_item_bg_1"/>
注意:这里如果没有设置主题的话就会报错TextView转换错误!
AndroidManifest.xml
|