Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android标题栏大小_Android_Titlebar - Fatal编程技术网

Android标题栏大小

Android标题栏大小,android,titlebar,Android,Titlebar,如何获取活动标题栏的大小和系统栏的大小?我使用我的根布局来获取,问题是当onCreate/onStart/onResume方法第一次运行时,您无法在其中获取此信息(宽度和高度) 在这之后的任何时刻,都可以从根布局(LinearLayout/FrameLayout/TableLayout/etc)检索大小,在我使用FrameLayout时: FrameLayout f = (FrameLayout) findViewById(R.id.layout_root); Log.d(TAG, "width

如何获取活动标题栏的大小和系统栏的大小?

我使用我的根布局来获取,问题是当onCreate/onStart/onResume方法第一次运行时,您无法在其中获取此信息(宽度和高度)

在这之后的任何时刻,都可以从根布局(LinearLayout/FrameLayout/TableLayout/etc)检索大小,在我使用FrameLayout时:

FrameLayout f = (FrameLayout) findViewById(R.id.layout_root);
Log.d(TAG, "width " + f.getMeasuredWidth() );
Log.d(TAG, "height " + f.getMeasuredHeight() );
或:

现在您已经知道了活动的高度,要知道系统栏的高度,只需从活动高度减去全屏高度即可

如何获得屏幕的高度在此处进行了说明:

从这里编辑--------------------------------------------------------

我找到了一种方法来获取关于onCreted方法的信息,但前提是您有多个活动。在我的例子中,我有一个称为第二个活动的主要活动

在调用第二个活动之前,通过一个新的Itent,我可以为第二个活动添加额外的信息。以下是您在第一个活动中需要的代码:

Intent i = new Intent(this, SecondActivity.class);
i.putExtra("width", f.getMeasuredWidth());
i.putExtra("height", f.getMeasuredHeight());
startActivity(i);
之后,在第二个活动中,您可以通过第二个活动的onCreate方法检索以下信息:

int width = getIntent().getExtras().getInt("width");
int height = getIntent().getExtras().getInt("height");
int width = getIntent().getExtras().getInt("width");
int height = getIntent().getExtras().getInt("height");