ID_ANDROID_CONTENT

原创 2015年11月18日 15:20:49

ID_ANDROID_CONTENT:The ID that the main layout in the XML layout file should have(XML中显示区域根视图的ID值,该视图由系统自动生成,未在XML中定义)


getTop、getBottom、getLeft、getRight:视图相对于父视图的位置


代码实例:

public class MainActivity extends Activity {

TextView mTextView;

Handler mHandler = new Handler() {

@Override

public void handleMessage(Message msg) {

if(msg.what == 0) {

int contentTop1 = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();

Log.e("wangzihan","" + contentTop1);

int contentTop2 = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getBottom();

Log.e("wangzihan","" + contentTop2);

int contentTop3 = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getLeft();

Log.e("wangzihan","" + contentTop3);

int contentTop4 = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getRight();

Log.e("wangzihan","" + contentTop4);

Rect frame = new Rect();

mTextView.getWindowVisibleDisplayFrame(frame);

Log.e("wangzihan"," " + frame.top + "  " + frame.bottom + " " + frame.left + " " + frame.right);

}

}

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

mTextView = (TextView)findViewById(R.id.a);

mHandler.sendEmptyMessageDelayed(0,1000);

}

}

// requestWindowFeature(Window.FEATURE_NO_TITLE);

// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

输出结果为

204

1920

0

1024

60  1920  0  1024

requestWindowFeature(Window.FEATURE_NO_TITLE);

// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

输出结果:

60

1920

0

1024

60  1920  0  1024


//requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

输出结果为

144

1920

0

1080

0  1920  0  1080


requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

输出结果为

0

1920

0

1080

0  1920  0  1080


int contentTop1 = getWindow().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();

Log.e("wangzihan","" + contentTop1);


int contentTop2 = getWindow().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getBottom();

Log.e("wangzihan","" + contentTop2);


int contentTop3 = getWindow().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getLeft();

Log.e("wangzihan","" + contentTop3);


int contentTop4 = getWindow().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getRight();

Log.e("wangzihan","" + contentTop4);


Rect frame = new Rect();

mInputView.getWindowVisibleDisplayFrame(frame);

Log.e("wangzihan"," " + frame.top + "  " + frame.bottom + " " + frame.left + " " + frame.right);


Log.e( "wangzihan","" + getWindow().getWindow().getDecorView().getTop() );

Log.e( "wangzihan","" + getWindow().getWindow().getDecorView().getBottom() );

Log.e( "wangzihan","" + getWindow().getWindow().getDecorView().getLeft() );

Log.e( "wangzihan","" + getWindow().getWindow().getDecorView().getRight() );


--------------------------------- 普通activity 有状态栏、标题栏

204

1920

0

1080

60 1920 0 1080

0

1920

0

1080

--------------------------------- 输入法 界面

0

731

0

1080

60 1920 0 1080

0

731

0

1080

getWindow().getWindow().getDecorView().setBackgroundDrawable(getResources().getDrawable(R.drawable.girl));  设置输入法window背景


Android点滴(二)

如何获取状态栏和标题栏的高度? 1.获取状态栏高度: decorView是window中的最顶层view,可以从window中获取到decorView,然后decorView有个getWindow...
  • xyz_fly
  • xyz_fly
  • 2012年06月14日 14:51
  • 2461

Android基于Window.ID_ANDROID_CONTENT给定id添加子View

基于Window.ID_ANDROID_CONTENT给定id添加子View这一技术特点在一些视频播放器中比较有用。例如代码:package zhangphil.demo; import andro...

android状态栏一体化(沉浸式状态栏)

Android 沉浸式状态栏、状态栏一体化、透明状态栏、仿ios透明状态栏  http://blog.csdn.net/jdsjlzx/article/details/50437779 注...
  • jhl122
  • jhl122
  • 2016年09月18日 16:01
  • 1129

android状态栏一体化(改变状态栏的背景颜色)

Android 沉浸式状态栏、状态栏一体化、透明状态栏、仿ios透明状态栏 http://blog.csdn.net/jdsjlzx/article/details/50437779 注:...

Activity中 findViewById 获取控件对象正确的代码位置

package com.xiuye.adnroid; import android.app.Activity; import android.content.Intent; import andro...

Android点滴(二)

如何获取状态栏和标题栏的高度? 1.获取状态栏高度: decorView是window中的最顶层view,可以从window中获取到decorView,然后decorView有个getWindow...
  • xyz_fly
  • xyz_fly
  • 2012年06月14日 14:51
  • 2461

android状态栏一体化(沉浸式状态栏)

Android 沉浸式状态栏、状态栏一体化、透明状态栏、仿ios透明状态栏  http://blog.csdn.net/jdsjlzx/article/details/50437779 注...
  • jhl122
  • jhl122
  • 2016年09月18日 16:01
  • 1129

android.content.res.Resources$NotFoundException: Resource ID #0x7f09000a type #0x12 is not valid

1.出现错误如下:2.分析:找不到XML资源: 网上找了一圈,大多是告诉你XML有编译期的错误,没有显示出来,如代码残缺,索引资源有问题,图片,字符,样式等等,如果是如此的问题,去一个个排查就好了,...

APK签名android.content.res.Resources$NotFoundException resource ID #0x7f060000

What steps will reproduce the problem? 1. Decode an app with a raw resource (such as an MP3) 2. Buil...
  • WHACKW
  • WHACKW
  • 2015年02月05日 18:17
  • 1276

android.content.res.Resources$NotFoundException: Resource ID #0x7f030002

1、错误产生 今天写了小demo,想预览下
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ID_ANDROID_CONTENT
举报原因:
原因补充:

(最多只允许输入30个字)