Android get color as string value

前端 未结 11 1491
青春惊慌失措
青春惊慌失措 2021-01-30 19:28

If i defined a color in resources


    #123456

it\'s possible

11条回答
  •  有刺的猬
    2021-01-30 19:54

    Add @SuppressLint("ResourceType") if an error occurs. Like bellow.

    private String formatUsernameAction(UserInfo userInfo, String action) {
            String username = userInfo.getUsername();
            @SuppressLint("ResourceType") String usernameColor = getContext().getResources().getString(R.color.background_button);
            return "" + username
                    + " " + action.toLowerCase() + "";
        }
    

提交回复
热议问题