安卓开发一些基础的设置代码.docx
《安卓开发一些基础的设置代码.docx》由会员分享,可在线阅读,更多相关《安卓开发一些基础的设置代码.docx(28页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、安卓开发一些基础的设置代码DialogFragment 设置背景透明onCreateViewWindow window = getDialog().getWindow();if (window != null) window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT);简单的 btn 状态选择器Fragment 和 Activity 的交互需要注意的是 getActivity() 有可能会返回 nullView xxx = getActivity().findViewById(R.id.xxx);获得 fragment
2、的引用要用 FragmentManager,之后可以调用 findFragmentById() 或者 findFragmentByTag()ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment);事件回调一些情况下,可能需要 fragment 和 activity 共享事件,一个比较好的做法是在 fragment 里面定义一个回调接口,然后要求 activity 实现它,当 activity通过这个接口接收到一个回调,它可以同布局中的其他
3、fragment 分享这个信息。监听 Fragment Back 的两个方法 写回调实现 判断 RootView Override public void onResume() super.onResume(); getView().setFocusableInTouchMode(true); getView().requestFocus(); getView().setOnKeyListener(new View.OnKeyListener() Override public boolean onKey(View v, int keyCode, KeyEvent event) if (eve
4、nt.getAction() = KeyEvent.ACTION_UP return false; ); 调用市场 playUri uri = Uri.parse(“market:/details?id=“ + context.getPackageName();Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);try startActivity(goToMarket); catch (ActivityNotFoundException e) 自定义 View(1 )定义一个 Class 继承于系统 View;(2 )在 xml 中配
5、置 layout 布局文件;(3 )重写父类的一些方法,如 onMeasure、onDraw、onLayout 等;(4 )在程序中应用自定义的 View;onMeasure()用来设置视图的大小,即视图的宽度和高度onLayout()用于设置视图在屏幕中显示的位置onDraw()利用前面两部分得到的参数,将视图显示在屏幕上android 的设计模式模版模式每次新建一个 Activity 时都会覆盖 onCreate(),onStart()方法等,这些方法在父类中就相当于一个模板观察者模式点击事件适配器模式adapter单例模式Application工厂模式BitmapFactory.deco
6、deResource();BitmapFactory 相当于位图工厂代理模式AIDLLayout 属性android:clipToPadding:配合 paddingTop 可简单实现 View 距离顶部一定距离android:clipChildren:是否限制子 View 在其范围内调用显示触摸位置功能android.provider.Settings.System.putInt(getContentResolver(), “show_touches“, 1);代码切换全屏/切换到全屏 getWindow().clearFlags(WindowManager.LayoutParams.FLA
7、G_FORCE_NOT_FULLSCREEN);getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);/切换到非全屏getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);Activity 透明android:color/transparentnulltruetruenull展开、收起状态栏pu
8、blic static final void collapseStatusBar(Context ctx) Object sbservice = ctx.getSystemService(“statusbar“);try Class statusBarManager = Class.forName(“android.app.StatusBarManager“);Method collapse;if (Build.VERSION.SDK_INT = Build.VERSION_CODES.JELLY_BEAN_MR1) collapse = statusBarManager.getMethod(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 开发 一些 基础 设置 代码
限制150内