本文整理汇总了Java中android.view.WindowManager.LayoutParams类的典型用法代码示例。如果您正苦于以下问题:Java LayoutParams类的具体用法?Java LayoutParams怎么用?Java LayoutParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LayoutParams类属于android.view.WindowManager包,在下文中一共展示了LayoutParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = this.getIntent();
Bundle bl = intent.getExtras();
if (bl != null) {
title = bl.getString(KEY_TITILE);
mDir = bl.getString(KEY_PATH);
}
setTitle(title);
mData = getData();
MyAdapter adapter = new MyAdapter(this);
setListAdapter(adapter);
getListView().setOnScrollListener(listener);
// 固定对话框大小
LayoutParams p = getWindow().getAttributes();
p.height = (int) (getResources().getDisplayMetrics().heightPixels * 0.8);
p.width = (int) (getResources().getDisplayMetrics().widthPixels * 0.95);
getWindow().setAttributes(p);
}
示例2: centerWindow
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private static void centerWindow(Window w) {
DisplayMetrics metrics = new DisplayMetrics();
Display display = w.getWindowManager().getDefaultDisplay();
display.getMetrics(metrics);
int width = Math.min(metrics.widthPixels - (int) (2 * DLG_PADDING_DP * metrics.density),
(int) (MAX_DIALOG_WIDTH_DP * metrics.density));
int height = Math.min(metrics.heightPixels - (int) ((2 * DLG_PADDING_DP + APPROX_STATUSBAR_HEIGHT_DP) * metrics.density),
(int) (MAX_DIALOG_HEIGHT_DP * metrics.density));
int x = (metrics.widthPixels - width) / 2;
int y = (metrics.heightPixels - height - ((int) (APPROX_STATUSBAR_HEIGHT_DP * metrics.density))) / 2;
LayoutParams params = w.getAttributes();
params.x = x;
params.y = y;
params.width = width;
params.height = height;
w.setAttributes(params);
w.setGravity(Gravity.LEFT | Gravity.TOP);
}
示例3: setBrightness
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private void setBrightness(double brightness) {
if (brightness > BRIGHTNESS_MAX_LEVEL) {
Logger.getInstance().Error(TAG, "Brightness to high! Set to maximum level!");
brightness = BRIGHTNESS_MAX_LEVEL;
}
if (brightness < BRIGHTNESS_MIN_LEVEL) {
Logger.getInstance().Error(TAG, "Brightness to low! Set to minimum level!");
brightness = BRIGHTNESS_MIN_LEVEL;
}
ContentResolver contentResolver = _context.getContentResolver();
Window window = ((Activity) _context).getWindow();
try {
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, (int) (brightness * 255));
LayoutParams layoutParams = window.getAttributes();
layoutParams.screenBrightness = (float) brightness;
window.setAttributes(layoutParams);
} catch (Exception e) {
Logger.getInstance().Error(TAG, e.toString());
Toasty.error(_context, "Failed to set brightness!", Toast.LENGTH_SHORT).show();
}
}
示例4: displayListViewDialog
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private static void displayListViewDialog(@NonNull Context context, @NonNull String title, @NonNull ArrayList<String> list) {
final android.app.Dialog dialog = new android.app.Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_listview);
TextView titleView = dialog.findViewById(R.id.dialog_title_text_view);
titleView.setText(title);
com.rey.material.widget.Button closeButton = dialog.findViewById(R.id.dialog_button_close);
closeButton.setOnClickListener(v -> dialog.dismiss());
ListView listView = dialog.findViewById(R.id.dialog_list_view);
listView.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_dropdown_item_1line, list));
dialog.setCancelable(true);
dialog.show();
Window window = dialog.getWindow();
if (window != null) {
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
}
示例5: addTabViewToWindow
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private void addTabViewToWindow(View view, int x, int y, int w, int h, Boolean touchable) {
int flags = 16843544;
if (!touchable.booleanValue()) {
flags = 16843544 | 16;
}
LayoutParams params = new LayoutParams(-2, -2, 2007, flags, -3);
params.gravity = 51;
params.width = w;
params.height = h;
params.x = x;
params.y = y;
try {
Field privateFlags = params.getClass().getDeclaredField("privateFlags");
privateFlags.setInt(params, privateFlags.getInt(params) | 64);
} catch (NoSuchFieldException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex2) {
ex2.printStackTrace();
}
getWindowManager().addView(view, params);
}
示例6: addInboxBodyToWindow
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
void addInboxBodyToWindow(int windowType) {
if (windowType == 2010 || windowType == 2007) {
Log.d(TAG, "add Tray()");
WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
LayoutParams params = new LayoutParams(-2, -2, windowType, 16843544, -3);
params.gravity = 51;
params.width = -1;
params.height = -1;
params.x = (int) FAR_AWAY;
params.y = 0;
windowManager.addView(this.shadeInboxBody, params);
this.shadeInboxBody.setVisibility(View.INVISIBLE);
return;
}
Log.d(TAG, "Unrecognized Window Type: addInboxBodyToWindow()");
}
示例7: show
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
public void show(IBinder windowToken) {
MenuBuilder menu = this.mMenu;
Builder builder = new Builder(menu.getContext());
this.mPresenter = new ListMenuPresenter(builder.getContext(), R.layout.abc_list_menu_item_layout);
this.mPresenter.setCallback(this);
this.mMenu.addMenuPresenter(this.mPresenter);
builder.setAdapter(this.mPresenter.getAdapter(), this);
View headerView = menu.getHeaderView();
if (headerView != null) {
builder.setCustomTitle(headerView);
} else {
builder.setIcon(menu.getHeaderIcon()).setTitle(menu.getHeaderTitle());
}
builder.setOnKeyListener(this);
this.mDialog = builder.create();
this.mDialog.setOnDismissListener(this);
LayoutParams lp = this.mDialog.getWindow().getAttributes();
lp.type = CloseFrame.REFUSE;
if (windowToken != null) {
lp.token = windowToken;
}
lp.flags |= 131072;
this.mDialog.show();
}
示例8: createWindowLayoutParams
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private LayoutParams createWindowLayoutParams() {
LayoutParams lp = new LayoutParams();
if (VERSION.SDK_INT >= 19) {
lp.type = 2005;
} else {
lp.type = 2002;
}
lp.flags |= 8;
lp.alpha = 1.0f;
lp.gravity = 83;
lp.x = 0;
lp.y = 0;
lp.width = FLOATING_WINDOW_WIDTH;
lp.height = FLOATING_WINDOW_HEIGHT;
lp.format = 1;
return lp;
}
示例9: a
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private void a() {
this.b = new TextView(this.a.F);
this.b.setTextColor(Color.rgb(255, 255, 255));
this.b.setTextSize(15.0f);
this.b.setShadowLayer(1.0f, 1.0f, 1.0f, Color.rgb(242, 211, 199));
this.b.setGravity(3);
this.b.setEllipsize(TruncateAt.END);
this.b.setIncludeFontPadding(false);
this.b.setSingleLine(true);
ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, -2);
layoutParams.weight = 1.0f;
layoutParams.leftMargin = this.a.a(4);
addView(this.b, layoutParams);
this.c = new Button(this.a.F);
this.c.setPadding(0, 0, 0, 0);
this.c.setTextSize(16.0f);
this.c.setTextColor(Color.rgb(255, 255, 255));
this.c.setShadowLayer(1.0f, 1.0f, 1.0f, Color.rgb(242, 211, 199));
this.c.setIncludeFontPadding(false);
this.c.setOnClickListener(new f(this.a, this.d.a));
layoutParams = new LinearLayout.LayoutParams(this.a.a(TaskGuide.p), this.a.a(TaskGuide.q));
layoutParams.leftMargin = this.a.a(2);
layoutParams.rightMargin = this.a.a(8);
addView(this.c, layoutParams);
}
示例10: b
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
private ViewGroup b(Context context) {
ViewGroup eVar = new e(this, context);
g[] gVarArr = this.h.c;
View iVar;
ViewGroup.LayoutParams layoutParams;
if (gVarArr.length == 1) {
iVar = new i(this, context, gVarArr[0]);
iVar.setId(1);
layoutParams = new RelativeLayout.LayoutParams(-1, -2);
layoutParams.addRule(15);
eVar.addView(iVar, layoutParams);
} else {
iVar = new i(this, context, gVarArr[0]);
iVar.setId(1);
View iVar2 = new i(this, context, gVarArr[1]);
iVar2.setId(2);
layoutParams = new RelativeLayout.LayoutParams(-1, -2);
layoutParams.addRule(14);
layoutParams.setMargins(0, a(6), 0, 0);
ViewGroup.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, -2);
layoutParams2.addRule(14);
layoutParams2.setMargins(0, a(4), 0, 0);
layoutParams2.addRule(3, 1);
layoutParams2.addRule(5, 1);
eVar.addView(iVar, layoutParams);
eVar.addView(iVar2, layoutParams2);
}
eVar.setBackgroundDrawable(e());
return eVar;
}
示例11: onCreate
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.flashlight);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
SettingsApplication app = (SettingsApplication) getApplication();
String value = app.getPreferences().getString(Constants.PREF_FLASHLIGHT_SWITCH, "0");
switch (Integer.parseInt(value)) {
case 1:
mSwitchDetector = new DelaySwitchDetector(this);
break;
case 2:
mSwitchDetector = new ShakeSwitchDeterctor(this);
break;
default:
mSwitchDetector = new OrientationSwitchDetector(this);
break;
}
mMessage = (TextView) findViewById(R.id.text);
mMessage.setText(mSwitchDetector.getTextId());
}
示例12: run
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
public void run() {
RangeSetting setting = (RangeSetting) mSetting;
// convert from 100 basis to 255 basis
int value = getPropertyValue(setting.value);
// update current view's brightness
LayoutParams attrs = mAttrs;
if (attrs == null) {
attrs = mActivity.getWindow().getAttributes();
mAttrs = attrs;
}
attrs.screenBrightness = value / (float)getMaximum();
// request brightness update
Window window = mActivity.getWindow();
window.setAttributes(attrs);
}
示例13: setAutobrightness
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
protected void setAutobrightness(Activity activity, ContentResolver resolver, boolean on) {
super.setAutobrightness(activity, resolver, on);
// set auto brightness on/off
int value = on ? 255 : 128; // auto or middle brightness
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, value);
if (!on) {
// update slider
RangeSetting setting = (RangeSetting) mSetting;
setting.value = getPercentValue(value);
setting.descr = null;
setting.enabled = false;
setting.checked = false;
setting.updateView();
}
// update current view's brightness
LayoutParams attrs = mActivity.getWindow().getAttributes();
attrs.screenBrightness = on ? 1f : value / (float) getMaximum();
// request brightness update
Window window = mActivity.getWindow();
window.setAttributes(attrs);
}
示例14: FileChooser
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
public FileChooser(Activity activity, File initialPath) {
this.activity = activity;
dialog = new Dialog(activity);
list = new ListView(activity);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
String fileChosen = (String) list.getItemAtPosition(which);
File chosenFile = getChosenFile(fileChosen);
if (chosenFile.isDirectory()) {
refresh(chosenFile);
} else {
if (fileListener != null) {
fileListener.fileSelected(chosenFile);
}
dialog.dismiss();
}
}
});
dialog.setContentView(list);
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
if (initialPath != null) {
refresh(initialPath);
}else{
refresh(Environment.getExternalStorageDirectory());
}
}
示例15: setStatusBarDarkIcon
import android.view.WindowManager.LayoutParams; //导入依赖的package包/类
public static boolean setStatusBarDarkIcon(Window window, boolean dark) {
if (window == null) {
return false;
}
try {
LayoutParams lp = window.getAttributes();
Field darkFlag = LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
Field meizuFlags = LayoutParams.class.getDeclaredField("meizuFlags");
darkFlag.setAccessible(true);
meizuFlags.setAccessible(true);
int bit = darkFlag.getInt(null);
int value = meizuFlags.getInt(lp);
if (dark) {
value |= bit;
} else {
value &= bit ^ -1;
}
meizuFlags.setInt(lp, value);
window.setAttributes(lp);
return true;
} catch (Exception e) {
Log.e(TAG, "setStatusBarDarkIcon: failed");
return false;
}
}