常用语句

1、设置全屏显示

2、获取当天的周期

3、设置状态栏半透明

4、设置状态栏全透明

5、使用Gson解析数据

6、获取屏幕高宽、ImageView的宽高

7、时间戳转北京时间

8、RecyclerView的引入依赖和适配器依赖

设置全屏显示:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

 获取当天的周期:

Date date = new Date();
SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
String currSun = dateFm.format(date); //获取当前周期

 设置状态栏半透明

        //半透明信息栏
        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } 

 设置状态栏全透明

//全透明信息栏
        if(Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.setStatusBarColor(Color.TRANSPARENT);
        }    

 隐藏默认标题栏(在styles.xml中加入以下红框中的两行代码):

 

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

使用gson解析数据:

先加入Gson依赖

implementation 'com.google.code.gson:gson:2.8.5'

Json串转String型

Gson gson = new Gson();
String name = gson.toJson(nameList);

Json串转成单个java对象(Name实体类)

Name name = gson.fromJson(nameList,Name.class);

解析String型数据(String name)

List list = gson.fromJson(name,new TypeToken<List<String>>(){}.getType());

获取屏幕的高宽:

Point point = new Point();
getWindowManager().getDefaultDisplay().getRealSize(point);
int width = point.x; //当前屏幕的宽度
int height = point.y; //当前屏幕的高度

获取ImageView宽高

ViewGroup.LayoutParams params = img.getLayoutParams();
int width= params.width; 
int height = params.height;

时间戳转北京时间(格式为:2020-07-27 17:29:03):

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = format.format(System.currentTimeMillis());

  

RecyclerView的引入依赖和适配器依赖:

implementation 'androidx.recyclerview:recyclerview:1.0.0'//recycleView
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.49'//recycleView适配器

  

原文地址:https://www.cnblogs.com/Mr-Deng/p/11173340.html