




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android中怎么禁止状态栏下拉
Android中怎么禁止状态栏下拉,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面在下将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。1.修改SystemUI路径:==/frameworks/base/packages/SystemUI//src/com/android/systemui/statusbar/phone/PhoneStatusBar.Java==通过在PhoneStatusBar.java类中注册一个广播的方式来实现状态栏的禁用和解除,其核心方法就是调用了disable()方法。disable()是SystemUI自定义的方法,感兴趣的同学可以去看其具体实现。下面来看下我们在SystemUI中的具体实现代码:@@
-494,6
+494,31
@@
public
class
PhoneStatusBar
extends
BaseStatusBar
implements
DemoMode
{
}
+
//add
steven
zhang
by
20160701
+
private
BroadcastReceiver
mStatusShowHide
=
new
BroadcastReceiver()
{
+
+
@Override
+
public
void
onReceive(final
Context
context,
Intent
intent)
{
+
//
TODO
Auto-generated
method
stub
+
String
action
=
intent.getAction();
+
+
if
("com.aura.statusbar.SHOW_OR_HIDE".equals(action))
{
+
//
StatusBarManager.DISABLE_NONE
+
//
StatusBarManager.DISABLE_EXPAND
+
final
int
mode
=
intent.getIntExtra("mode",
StatusBarManager.DISABLE_NONE);
+
if
(mNavigationBarView
!=
null)
{
+
mHandler.post(new
Runnable()
{
+
+
@Override
+
public
void
run()
{
+
+
disable(mode);
+
}
+
});
+
}
+
}
+
}
+
};
//micheal
add
the
Broadcast
interface
for
Control
the
wifi
sleep
mode
change
begin
20150514
private
BroadcastReceiver
wifiSleepModeChangeReceiver
=
new
BroadcastReceiver(){
@Override
@@
-519,6
+544,10
@@
public
class
PhoneStatusBar
extends
BaseStatusBar
implements
DemoMode
{
//
================================================================================
protected
PhoneStatusBarView
makeStatusBarView()
{
final
Context
context
=
mContext;
+
//
add
steven
zhang
by
20160701
+
IntentFilter
statusFilter
=
new
IntentFilter();
+
statusFilter.addAction("com.aura.statusbar.SHOW_OR_HIDE");
+
context.registerReceiver(mStatusShowHide,
statusFilter);既然显示隐藏的广播我们已经注册好了,那么看下我们在APP中的具体调用吧。@Override
protected
void
onResume()
{
super.onResume();
Intent
i
=
new
Intent("com.aura.statusbar.SHOW_OR_HIDE");
i.putExtra("mode",
StatusBarManager.DISABLE_EXPAND);
sendBroadcast(i);
}
@Override
protected
void
onPause()
{
super.onPause();
Intent
i
=
new
Intent("com.aura.statusbar.SHOW_OR_HIDE");
i.putExtra("mode",
StatusBarManager.DISABLE_NONE);
sendBroadcast(i);
}在Activity中重写onResume和onPause方法实现状态栏的禁用和解除禁用。另:StatusBarManager是一个隐藏类,所以调用的时候可能导入不了包会报错,最简单的方法就是之间用数值替换,下面列出对应关系。public
static
final
int
DISABLE_EXPAND
=
0x00010000;
public
static
final
int
DISABLE_NOTIFICATION_ICONS
=
0x00020000;
public
static
final
int
DISABLE_NOTIFICATION_ALERTS
=
0x00040000;
public
static
final
int
DISABLE_NOTIFICATION_TICKER
=
0x00080000;
public
static
final
int
DISABLE_SYSTEM_INFO
=
0x00100000;
public
static
final
int
DISABLE_HOME
=
0x00200000;
public
static
final
int
DISABLE_RECENT
=
0x01000000;
public
static
final
int
DISABLE_BACK
=
0x00400000;
public
static
final
int
DISABLE_CLOCK
=
0x00800000;
public
static
final
int
DISABLE_SEARCH
=
0x02000000;
public
static
final
int
DISABLE_NONE
=
0x00000000;
public
static
final
int
DISABLE_NAVIGATION
=
View.STATUS_BAR_DISABLE_HOME
|
View.STATUS_BAR_DISABLE_RECENT;
public
static
final
int
DISABLE_MASK
=
DISABLE_EXPAND
|
DISABLE_NOTIFICATION_ICONS
|
DISABLE_NOTIFICATION_ALERTS
|
DISABLE_NOTIFICATION_TICKER
|
DISABLE_SYSTEM_INFO
|
DISABLE_RECENT
|
DISABLE_HOME
|
DISABLE_BACK
|
DISABLE_CLOCK
|
DISABLE_SEARCH;所以不能引用StatusBarManager的同学之间使用其数值是一样的。如果有源码的朋友,可以使用系统编译的后frameworkjar包作为APP的lib就可以直接使用StatusBarManager方法了。其路径为/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar。将classes.jar改为framework.jar导入工程就OK了。通过上面的步骤我们知道最关键的就是调用PhoneStatusBar中disable()方法,我们这里是以广播的方式实现的,任何有新方法的同学可以脑洞大开,只要能实现调用到disable()就可以禁用状态栏。2.修改PhoneWindowManager路径:==/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java==//
monitor
for
system
gestures
mSystemGestures
=
new
SystemGesturesPointerEventListener(context,
new
SystemGesturesPointerEventListener.Callbacks()
{
@Override
public
void
onSwipeFromTop()
{
if
(isGestureIsolated())
return;
if
(mStatusBar
!=
null)
{
requestTransientBars(mStatusBar);
}
}
@Override
public
void
onSwipeFromBottom()
{
if
(isGestureIsolated())
return;
if
(mNavigationBar
!=
null
&&
mNavigationBarOnBottom)
{
requestTransientBars(mNavigationBar);
}
}
@Override
public
void
onSwipeFromRight()
{
if
(isGestureIsolated())
return;
if
(mNavigationBar
!=
null
&&
!mNavigationBarOnBottom)
{
requestTransientBars(mNavigationBar);
}
}
@Override
public
void
onDebug()
{
//
no-op
}
private
boolean
isGestureIsolated()
{
boolean
ret
=
false;
ret
=
Settings.System.getInt(mContext.getContentResolver(),"status_bar_disabled",
0)
==
1;
return
ret;
}
});在SystemGesturesPointerEventListener.Callbacks的方法中增加一个判断函数isGestureIsolated()用于判断是否支持其对应的手势操作。在这里特别说明一下,在网上找到方法用private
boolean
isGestureIsolated()
{
boolean
ret
=
false;
WindowState
win
=
mFocusedWindow
!=
null
?
mFocusedWindow:mTopFullscreenOpaqueWindowState;
if
(win
!=
null
&&
(win.getSystemUiVisibility()
&
View.SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED)
!=
0)
ret
=
true;
else
ret
=
false;
return
ret;
}getSystemUiVisibility()这种方式做判断的时候,获取到的win不一定是当前activity的,有时候是statusbar的,所以这样的效果不是很好,经常会下拉出状态栏,于是就有了Settings.System.getInt(mContext.getContentResolver(),"status_bar_disabled",
0)
==
1;做判断的方法,用这种方式有一个好处就是非常直接,需要它禁止下拉的时候,就调用Settings.System.putInt(getContentResolver(),
"status_bar_disabled",
1);就OK了,解除禁止的时候调用Settings.System.putInt(getContentResolver(),
"status_bar_disabled",
0);看下Activity中的具体调用@Override
protected
void
onResume()
{
super.onResume();
//禁止下拉
Settings.System.putInt(getContentResolver(),
"status_bar_disabled",
1);
}
@Override
protected
void
onPause()
{
super.onPause();
//解除禁止
Settings.System.putInt(getContentResolver(),
"status_bar_disabled",
0);
}在AndroidManifest.xml中声明相应的权限<uses-permission
android:name="android.permission.WRITE_SETTINGS"
/>网上还有修改PhoneWindowManager中的adjustSystemUiVisibilityLw方法的,如:@Override
public
int
adjustSystemUiVisibilityLw(int
visibility){
if
(Settings.System.getInt(mContext.getContentResolver(),"status_bar_disabled",
0)
==
0)
{
mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags,
visibility);
}
mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags,
visibility);
//
Reset
any
bits
in
mForceClearingStatusBarVisibility
that
//
are
now
clear.
mResettingSystemUiFlags
&=
visibility;
//
Clear
any
bits
in
the
new
visibility
that
are
currently
being
//
force
cleared,
before
reporting
it.
return
visibility
&
~mResettingSystemUiFlags
&
~mForceClearedSystemUiFlags;
}在adjustSystemUiVisibilityLw增加一个标志的判断,但这种实现的效果也不是很好,还是会出现下拉能拉下来的情况。综上所叙,修改PhoneWindowManager实现禁止下拉的方法还是在SystemGesturesPointerEventListener.Callbacks中增加一个内部方法,这个内部方法使用标志位的形式来判断是否支持状态栏下拉。3.使用StatusBarManager中方法因为StatusBarManager是隐藏方法,所以要在IDE中直接使用的话要导入frameworkjar包,怎么找到frameworkjar在1.修改SystemUI中有说过,这里就不重复了。直接上代码:1.在AndroidManifest.xml中声明相应的权限<uses-permission
android:name="android.permission.STATUS_BAR"/>
<uses-permission
android:name="android.permission.EXPAND_STATUS_BAR"/>网上有文章说要声明android
:
sharedUserId="android.uid.system"亲自测试没有加上面这行代码,也是可以使用的。2.在Activity中的引用@Override
protected
void
onResume()
{
super.onResume();
StatusBarManager
statusBarManager
=
(StatusBarManager)
getSystemService(Context.STATUS_BAR_SERVICE);
statusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
}
@Override
protected
void
onPause()
{
super.onPause();
StatusBarManager
statusBarManager
=
(StatusBarManager)
getSystemService(Context.STATUS_BAR_SERVICE);
statusBarManager.disable(StatusBarManager.DISABLE_NONE);
}1.是使用系统签名,编译为系统appjava
-jar
signapk.jar
platform.x
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年消防设施操作员之消防设备基础知识押题练习试题A卷含答案
- 小学重点考试试题及答案
- AI智慧城市建设与城市管理优化研究
- 办公系统使用简明教程与操作手册
- 个人办公用品采购合同规范
- 现代物理学理论前沿探讨阅读题集
- 数字化图书馆建设协议
- 中医药儿童知识培训课件
- 马匹买卖合同
- 物理光学及量子力学考点复习题集
- 《工会基础知识试题及答案》600题
- 桑树栽培与管理课件
- 信用风险管理讲义课件
- 健康体检报告基本规范
- 多项式乘以多项式-完整版课件
- 衡水志臻实验中学小升初英语真题(一)
- 信息技术ppt课件完整版
- 《为梦想插上翅膀》课件
- 《防止电力建设工程施工安全事故三十项重点要求》
- 外研版九年级英语下册Module-4-Unit-2教学课件(PPT 16页)
- 精品随班就读个别化教学计划
评论
0/150
提交评论