问题:如何修改Android的Activity的转场动画?

解决:Android5.0前需要自己写,5.0后使用自带的就好

方法:

Andoid5.0之后

当前的Activity中

public void explode(View view) {
    Intent intent = new Intent(this, NextTransitionActivity.class);
    intent.putExtra("flag", "explode");
    startActivity(intent,
            ActivityOptionsCompat.makeSceneTransitionAnimation(this).toBundle());
}

public void slide(View view) {
    Intent intent = new Intent(this, NextTransitionActivity.class);
    intent.putExtra("flag", "slide");
    startActivity(intent,
            ActivityOptionsCompat.makeSceneTransitionAnimation(this).toBundle());
}

public void fade(View view) {
    Intent intent = new Intent(this, NextTransitionActivity.class);
    intent.putExtra("flag", "fade");
    startActivity(intent,
            ActivityOptionsCompat.makeSceneTransitionAnimation(this).toBundle());
}

阅读全文

问题:安卓如何实现透明状态栏,沉浸式状态栏/变色状态栏?

方法:

在BaseActivity中调用下面两方法,并设置每个Activity需要显示的颜色

/**
 * 全透状态栏
 */
protected void setStatusBarFullTransparent() {
    if (Build.VERSION.SDK_INT >= 21) {//21表示5.0
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    } else if (Build.VERSION.SDK_INT >= 19) {//19表示4.4
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //虚拟键盘也透明
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
}

阅读全文

问题:如何使用Gson将对象数组转换成json格式的数组?

方法:

String jsonList="[{'userid':'1001','username':'张三','usersex':'男','banji':'计算机1班','phone':'1213123'},"
+ "{'userid':'1002','username':'李四','usersex':'男','banji':'计算机1班','phone':'232323'},"
+ "{'userid':'1003','username':'王五','usersex':'男','banji':'计算机1班','phone':'432423423'}]";
Gson gson1=new Gson();
List<Person> list= gson1.fromJson(jsonList, new TypeToken<List<Person>>() {}.getType());
for (Person person1 : list) {
    System.out.println(person1.toString());
}

阅读全文

问题:FastAPI的HTTPException中有detail,如何去?

解决:重新定义HTTPException,及验证用的RequestValidationError

方法:

from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import JSONResponse
from fastapi.exceptions import RequestValidationError
from routers import router

app = FastAPI()
async def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
    return JSONResponse(
        status_code=exc.status_code,
        content=exc.detail)

阅读全文

问题:ubuntu终端输入异常,回退变空格

解决:缺少ncurses-base软件,因为安装mysql-workbench时安装了一堆的依赖,安装的依赖中有一个libncursesw5,安装这玩意儿会导致系统默认的ncurses-base被卸载…

方法:

sudo apt install ncurses-base
重启终端

阅读全文