Media資源轉(zhuǎn)element
public static PixelMapElement mediaResToPixel(Context context, int resId) {
try {
Resource resource = context.getResourceManager().getResource(resId);
ImageSource source = ImageSource.create(resource, null);
ImageSource.DecodingOptions opts = new ImageSource.DecodingOptions();
opts.desiredSize = new Size(48,48);
PixelMap pixelMap = source.createPixelmap(opts);
return new PixelMapElement(pixelMap);
} catch (IOException | NotExistException e) {
e.printStackTrace();
}
return null;
}
ScrollView嵌套ListContainer

ScrollView嵌套ListContainer
使用 Fraction
// 獲取存儲的狀態(tài),防止頁面重疊
@Override
public void onRestoreAbilityState(PacMap inState) {
super.onRestoreAbilityState(inState);
int index = inState.getIntValue("stateTag", 0);
changeFraction(index);
}
@Override
public void onSaveAbilityState(PacMap outState) {
outState.putIntValue("stateTag", selectIndex);
super.onSaveAbilityState(outState);
}
//隱藏Fraction
private void hideFraction(FractionScheduler fractionScheduler) {
if (homeFraction != null) fractionScheduler.hide(homeFraction);
if (matchFraction != null) fractionScheduler.hide(matchFraction);
if (mineFraction != null) fractionScheduler.hide(mineFraction);
}
// 顯示Fraction
private void changeFraction(int index) {
selectIndex = index;
FractionScheduler scheduler = fManager.startFractionScheduler();
hideFraction(scheduler);
switch (index) {
case 0:
if (homeFraction == null) {
homeFraction = new HomeFraction();
scheduler.add(ResourceTable.Id_fraction_main, homeFraction);
} else {
scheduler.show(homeFraction);
}
break;
case 1:
if (matchFraction == null) {
matchFraction = new MatchFraction();
scheduler.add(ResourceTable.Id_fraction_main, matchFraction);
} else {
scheduler.show(matchFraction);
}
break;
case 2:
if (mineFraction == null) {
mineFraction = new MineFraction();
scheduler.add(ResourceTable.Id_fraction_main, mineFraction);
} else {
scheduler.show(mineFraction);
}
break;
}
scheduler.submit();
}
隱藏 默認 title
"metaData": {
"customizeData": [
{
"name": "hwc-theme",
"value": "androidhwext:style/Theme.Emui.Light.NoTitleBar"
}
]
}
設置沉浸式狀態(tài)欄
getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
WindowManager.getInstance().getTopWindow().get().addFlags(WindowManager.LayoutConfig.MARK_ALLOW_EXTEND_LAYOUT);
設置狀態(tài)欄顏色
WindowManager.getInstance().getTopWindow().get().setStatusBarColor(Color.BLUE.getValue());
設置導航欄顏色
WindowManager.getInstance().getTopWindow().get().setNavigationBarColor(Color.GREEN.getValue());
設置沉浸式導航欄
在Ability或者 AbilitySlice中添加如下代碼(有如下幾種方式):
- getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_NAVIGATION);
- WindowManager.getInstance().getTopWindow().get().addFlags(WindowManager.LayoutConfig.FIRST_SYSTEM_WINDOW);
- WindowManager.getInstance().getTopWindow().get().addFlags(WindowManager.LayoutConfig.MOD_STATUS_BAR);
設置顯示狀態(tài)欄
WindowManager.getInstance().getTopWindow().get().setStatusBarVisibility(Component.VISIBLE);
設置隱藏狀態(tài)欄
- getWindow().addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN);
- WindowManager.getInstance().getTopWindow().get().setStatusBarVisibility(Component.INVISIBLE);
- WindowManager.getInstance().getTopWindow().get().addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN);
獲取屏幕寬度
public static int getDisplayWidthInPx(Context context) {
Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
Point point = new Point();
display.getSize(point);
return (int) point.getPointX();
}
獲取屏幕高度,不包含狀態(tài)欄的高度
public static float getDisplayHeightInPx(Context context) {
Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
Point point = new Point();
display.getSize(point);
return point.getPointY();
}
含狀態(tài)欄的高度
private float getRealHeight(Context context) {
Point point = new Point();
DisplayManager.getInstance().getDefaultDisplay(context).get().getRealSize(point);
float height = point.getPointY();
return height;
}
修改輸入框大小和樣式
ohos:element_cursor_bubble="$graphic:ele_cursor_bubble"
ohos:bubble_height="$float:vp_10"
ohos:bubble_width="$float:vp_10"