Android 中用到的功能集锦,方便以后备用,摘自各项目。
1.全屏与取消全屏(如手机有导航栏,需配合布局父容器fitsSystemWindows="true"使用)
private void setFullScreen() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
private void hideNavigationBar() {
// if (Build.VERSION.SDK_INT >= 19)
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= 16) {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
private void showNavigationBar() {
if (Build.VERSION.SDK_INT >= 16) {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
}
private void quitFullScreen() {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
cmake_minimum_required(VERSION 3.4.1) #指定编译器版本
set(PROJECT_NAME MyJni) #定义编译项目名称MyJni ,“PROJECT_NAME”为变量名
project (${PROJECT_NAME}) #设置编译项目名称
include_directories(src/main/cpp/include) #include头文件夹
#add_subdirectory(src/main/cpp/src/) #c/c++代码子文件夹
#定义所有c/c++文件(头文件不用)
set(SRC_RES src/main/cpp/native-lib.cpp)
#set(SRC_RES src/main/cpp/xxx.c)
#指定把源码编译进项目
add_library( ${PROJECT_NAME} SHARED
${SRC_RES})
#查找系统提供的库
find_library( log-lib
log )
set(LINK_LIB_DIR ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}) #设置导入的第三方.so库路径
add_library( avcodec SHARED IMPORTED) #添加导入的.so库
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${LINK_LIB_DIR}/libavcodec.so) #将库进行链接
#链接外部库
target_link_libraries( ${PROJECT_NAME}
${avcodec}
${log-lib} )