还剩30页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
怎样获取标题栏和状态栏高度获取状态栏高度L是中的最顶层可以从中获取到然后有个decorView windowview,window decorView,decorView措施可以获取到程序显示的区域,包括标题栏,但不包括状态栏getWindowVisibleDisplayFrame于是可以算出状态栏的高度了Rect frame=new Rect;getWindow.getDecorView.getWindowVisibleDisplayFrameframe;int statusBarHeight=frame.top;.获取标题栏高度2」这个措施获取至的就是程序不包括标题栏的部分,然getWindow.findViewByldWindow D_ANDROID_CONTENT Uview后就可以懂得标题栏的高度了int contentTop=getWindow.findViewByldWindow.lD_ANDROID_CONTENT.getTop;是上面所求的状态栏的高度//statusBarHeightint titleBarHeight=contentTop-statusBarHeight;让不能输入的措施EditTextViewetNearbySearch.setFiltersnew lnputFilter[]{new lnputFilter{@Overridepublic CharSequence filterCharSequence source,int start,int end,Spanned dest,int dstart,int dend{return source.Iength1dest.subSequencedstart,dend:;}}全屏问题,在程序一加载的时候就让它是全屏this.requestWindowFeatureWindow.FEATURE_NO_TITLE;this.getWindow.setFlagsWindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN;中这样写AndroidManifest.xmlactivity android:name=u.TextButtonActivity android:label=@string/app_nameandroid:theme=5anclroicl:style/Theme.NoTitleBar.Fullscreenprivate voidinitViewsetOnClickListenerthis;}/***〃***文本初始化,每次更改文本内容或者文本效果等之后都需要重新初始化一下*/public voidinitWindowManager windowManagerpaint=getPaint;text=getText.toString;textLength=paint.measureTexttext;viewWidth=getWidth;ifviewWidth==0ifwindowManager!=nullDisplay display=windowManager.getDefaultDisplay;viewWidth=display.getWidth;}step=textLength;te mp_vi ew_p Iu s_text_l en gth=viewWidth+textLength;temp_view_pIus_two_text_length=viewWidth+textLength*2;y=getTextSize+getPaddingTop;}@Overridepublic ParcelableonSavelnstanceStatefParcelable superstate=super.onSavelnstanceState;SavedState ss=new SavedStatesuperState;ss.step=step;ss.isStarting=isStarting;return ss;}©Overridepublic voidonRestorelnstanceStateParcelable stateif!state instanceofSavedState{super.onRestorelnstanceStatestate;return;SavedState ss=SavedStatestate;super.onRestorelnstanceStatess.getSuperState;step=ss.step;isStarting=ss.isStarting;public staticclass SavedStateextends BaseSavedState{public booleanisStarting=false;public floatstep=O.Of;SavedStateParcelable superstate{supersuperState;@Overridepublic voidwriteToParcelParcel out,int flags{super.writeToParcelout flags;out.writeBooleanArraynew boolean[]{isStarting};out.writeFloatstep;}public staticfinal Parcelable.CreatorSavedState CREATOR=new Parcelable.CreatorSavedState{public SavedState[]newArrayint size{return newSavedState[size];@Overridepublic SavedStatecreateFromParceIParceI in{return newSavedStatein;;}private SavedStateParcelin{superin;boolean[]b=null;in.readBooleanArrayb;ifb!=nullb.length0isStarting=b
[0];step=in.readFloat;}}/***〃***开始滚动*/public voidstartScrollisStarting=true;invalidate;/***〃***停止滚动*/public voidstopScrollisStarting=false;invalidate;@Overridepublic voidonDrawCanvas canvas{canvas.drawTexttext,temp_view_pIus_text_length-step,y,paint;ifiisStartingreturn;}step+=
0.5;ifsteptemp_view_pIus_two_text_length step=text Length;invalidate;@Overridepublic voidonClickView v{ifisStartingstopScroll;elsestartScroll;实现了宽度的判断,文本自动滚动及开始和停止滚动等功能在中的配置如下:UI xmlcn.tigertian.ui.AutoScrollTextView android:id=@+id/TextViewNotice android:layout_height=30pxandroid:layout_width=fill_parent android:text=@string/test_notice_l android:textColor=#000android:inputType=textandroid[background=#EEE”android:textSize=20px/cn.tigertian.ui.AutoScrollTextView在中的使用措施如下:Activity〃启动公告滚动条autoScrollTextView=AutoScrollTextViewfindViewByldR.id.TextViewNotice;autoScrollTextView.initgetWindowManager;autoScrollTextView.startScroll;假如想变化跑马灯的文字内容或者文字效果,则在调用完措施之后,需要再调用一下setText initWindowManager措施,重新进行初始化和有关参数的计算windowManagerj大概意思是@和?都是用来引用其他已经定义好的资源的@引用的是之前定义好的资源目前项目或者的android里而?则是引用的目前加载的样式文献里意思就是说你在里某行定义了一种资源,在下面某行需要framework xml引用这个资源时用?即可两种实现方式TabHost文章分类:编程Java第一种继承从中用措施获取只要定义详细内容布局就行了.TabActivity,TabActivity getTabHost TabHost Tab布局xml代码JavaFrameLayout xmlns:android=android:layout_width=fill_parentH android:layout_height=,,fill_parentLinearLayout android:id=H@+id/widgetJayout_Blueandroid:layout_width=fill_parent android:layout_height=fill_parentandroid:orientation=vertical EditTextandroid:id=,,@+id/widget34android:layout_width=,,fill__parentandroid:layout_height=wrap_content and roid:text=Ed itTextHandroid:textSize=18sp/EditTextButton android:id=@+id/widget30android:layout_width=wrap_contentandroid:layout_height=wrap_content android:text=Button/Button/LinearLayoutLinearLayout android:id=@4-id/widget_layout_redandroid:layout_width=fill_parent android:layout_height=fill_parentHandroid:orientation=verticar AnalogClockandroid:id=@+id/widget36android:layout_width=wrap_content android:layout_height=wrap_content/AnalogClock/LinearLayoutLinearLayout android:id=,,@+id/widgetjayout_greenandroid:layout_width=fill_parent android:layout_height=fill_parentandroid:orientation=verticalRadioGroup android:id=5+id/widget43android:layout_width=166px android:layout_height=98pxandroid:orientation=verticalRadioButton android:id=@+id/widget44android:layout_width=wrap_content android:layout_height=wrap_content android:text=,RadioButton/RadioButtonRadioButton android:id=@+id/widget45android:layout_width=wrap_content android:layout_height=wrap_content android:text=HRadioButton/RadioButton/RadioGroup/LinearLayout/FrameLayout代码javasuper.onCreatesavedlnstanceState;myTabhost=this.getTabHost;//get TabhostLayoutlnflater.fromthis.inflateR.layout.main,myTabhost.getTabContentView,true;myTabhost.setBackgroundColorColor.argb150,22,70,150;myTabhost.addTabmyTabhost.newTabSpecOne//make anew Tab.setlndicatorA//set theTitle andIcon.setContentR.id.widgetJayout_Blue;//set thelayoutmyTabhost.addTabmyTabhost.newTabSpecTwo//make anew Tab.setlndicatorCB,getResources.getDrawableR.drawable.mumule//set theTitle andIcon.setContentR.id.widget_layout_green;//set thelayoutmyTabhost.addTabmyTabhost.newTabSpecHThree//make anew Tab.setlndicatorC,getResources.getDrawableR.drawable.notepad//set theTitle andIcon.setContentR.id.widget_layout_red;FrameLayout xmlns:android=android:layout_width=fill_parent android:layout_height=Hfill_parentLinearLayout android:id=,@+id/widget_layout_Blueandroid:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical EditTextandroid:id=@+id/widget34android:layout_width=fill_parent android:layout_height=wrap_content android:text=Ed itTextandroid:textSize=18sp/EditTextButton android:id=@+id/widget30android:layout_width=wrap_contentandroid:layout__height=,,wrap_content android:text=Button/Button/LinearLayoutLinearLayout android:id=@+id/widget_layout_recTandroid:layout__width=fill_parent android:layout__height=Hfill_parent android:orientation=,,vertical AnalogClockandroid:id=@+id/widget36android:layout_width=wrap__content android:layout_height=nwrap_content/AnalogClock/LinearLayoutLinearLayout android:id=@+id/widgetjayout_greenandroid:layout_width=fill_parent android:layout_height=fill_parentandroid:orientation=verticalRadioGroup android:id=n@+id/widget43android:layout_width=166px android:layout_height=,,98px,,android:orientation=verticarRadioButton android:id=@+id/widget44”android:layout_width=wrap_content android:layout_height=wrap_contentandroid:text=RadioButton/RadioButtonRadioButton android:id=@+id/widget45android:layout_width=wrap__content android:layout_height=wrap__contentandroid:text=RadioButton/RadioButton/RadioGroup/LinearLayout/FrameLayout代码javasuper.onCreatesavedlnstanceState;myTabhost=this.getTabHost;//get TabhostLayoutlnflater.fromthis.inflateR.layout.main,myTabhost.getTabContentView,true;myTabhost.setBackgroundColorColor.argb150,22,70,150;myTabhost.addTabmyTabhost.newTabSpecOne//make anew Tab.setlndicatorA//set theTitle andIcon.setContentR.id.widget_layout_Blue;//set thelayoutmyTabhost.addTabmyTabhost.newTabSpecTwo//make anew Tab.setlndicatorfB,getResources.getDrawableR.drawable.mumule//set theTitle andIcon.setContentR.id.widget_layout_green;//set thelayoutmyTabhost.addTabmyTabhost.newTabSpecThree//make anew Tab.setlndicatorCH,getResources.getDrawableR.drawable.notepad//set theTitle andIcon.setContentR.id.widgetJayout_red;第二种不用继承在布局文献中定义即可,不过的必须是TabActivity,TabHost TabWidgetid@android:id/tabs,FrameLayout的必须是的可以自定义.id@android:id/tabcontent TabHostid布局xml代码Javaxml version=
1.0encoding=utf-8LinearLayout xmlns:android=android:id=@+id/hometabsandroid:orientation=verticarandroid:layout_width=,fill_parentHandroid:layout_height=fill_parentTabHost android:id=@+id/tabhostandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentLinearLayoutandroid:orientation=verticalandroid:layout_width=fill_parentandroid:layout_height=fill_parentTabWidget android:id=@android:id/tabs”android:orientation=Hhorizontalandroid:layout_width=wrap_content android:layout_height=wrap_content/TabWidgetFrameLayout android:id=5anclroicl:id/tabcontentandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentTextView android:id=@+id/viewl android:layout_width=fill_parent”android:layout_height=fill_parent/TextView android:id=@+id/view2android:layout_width=,,fill_parentH android:layout__height=fill_parent7TextView android:id=@+id/view3android:layout__width=,,fill_parent android:layout__height=filLparent//FrameLayout/LinearLayout/TabHost/LinearLayout代码javaprotected voidonCreateBundle savedlnstanceState{super.onCreatesavedlnstanceState;setContentViewR.layout.hometabs;TabHost tabHost=TabHost findViewByldR.id.tabhost;tabHost.setup;TabWidget tabWidget=tabHost.getTabWidget;tabHost.addTabtabHost.newTabSpectabl.setlndicatortabl,getResources.getDrawableR.drawable.mumule.setContentR.id.viewl;tabHost.addTabtabHost.newTabSpectab
3.setlndicatortab
3.setContentR.id.view3;tabHost.addTabtabHost.newTabSpectab
2.setlndicatortab
2.setContentR.id.view2;final inttabs=tabWidget.getChildCount;Log.iTAG,***tabWidget.getChildCount:+tabs;final inttabWidth=90;final inttabHeight=45;for inti=0;itabs;i++{/*final View view=tabWidget.getChildAti;view.getLayoutParams.width=tabWidth;view.getLayoutParams.height=tabHeight;final TextViewtv=TextView view.findViewByldandroid.R.id.title;tv.setTextColorthis.getResources.getColorStateListandroid.R.color.black;MarginLayoutParams tvMLP=MarginLayoutParamstv.getLayoutParams;tvMLP.bottomMargin=8;*/}显示图片和文字TextViewTextView text=TextView findViewByldR.id.TextViewOl;Drawable draw=this.getResources.getDrawableR.drawable.srvmng;text.setCompoundDrawablesWithlntrinsicBoundsnull,draw,null,null;应用;text.setText中我们为了实现文本的滚动可以在中嵌入一种其实自己也可以实现多行滚动的,Android ScrollviewTextView,TextView毕竟必须只能有一种直接的子类布局只要在中简朴设置几种属性就可以轻松实现ScrollView layoutTextViewandroickid=”@+id/tvCWJ”android:layout_width=fill_parentandroid:layout_height=wrap_content!--垂直滚动条-android:scrollbars=,vertical!--实现多行-android:singleLine=false!--最多不超过行android:maxLines=1515android:textColor=#FFOOOO/当然我们为了让动起来,还需要用到的措施设置一种滚动实例,代码如下TextView TextViewsetMovementMethodTextView tv=TextViewfindViewByldR.id.tvCWJ;tv.setMovementMethodScrollingMovementMethod.getlnstance;〉这样的类中class DownloadJSONTaskextends AsyncTaskString,Void,String不要在显示对话框,那个函数不会运行在线程上,试试在和显不dolnBackground UIonPostExecute onProgresslIpdate控件点击后,链接到一种网址ImageView img=lmageViewfindViewByldR.id.foo_bar;img.setOnClickListenernew View.OnClickListener{public voidonClickView v{Intent intent=new lntent;intent.setActionlntent.ACTION_VIEW;intent.addCategorylntent.CATEGORY_BROWSABLE;intent.setDataU^.parse,,,,;startActivityintent;};}里面文本设置加粗,底线等,使用格式,文本颜色的设置在文献里支持格式,你可以用TextView htmlxml html々,和13ix/iresourcestring name=your_string_here,lThis isan uunderline/u./string/resourcesxbx/b,ix/i andux/u.改成就可以了txtChange.setTextColor0xE01B4C;txtChange.setTextColor0xffE01B4C;调用记得在前面加上然后再加上颜色值setTextColorOxff,今晚有点时间把断了很长时间的开发补一下,这次实现的是像或者那样的气泡短信样式UI handcentsms chompsms给代码1listviewxml version=
1.0encoding=utf-8LinearLayout xmlns:android=,android:orientation=verticalandroid:layout_width=fill_parentandroid:layout__height=fill_parent,1android:background=,,@android:color/white ListViewandroid:layout_width=fill_parent android:layout_height=fill__parent android:divider=@nuir,android:dividerHeight=Odipandroid:cacheColorHint=#00000000android:listSelector=@drawable/listJtem_style android:id=@+id/itemlist//LinearLayout2ListView itemxml version=
1.0encoding=utf-8LinearLayoutxmlns:android=,^android:layout_width=wrap_content android:layout_height=wrap_contentTextView android:id=@+id/TextViewOl android:layout_width=,,wrap_content android:layout_height=wrap_contentandroid:textColor=@android:color/black android:background=@drawable/bg/TextView/LinearLayout3javapublic classHandcentList extendsActivity{/**Called whenthe activityis firstcreated.*/ListView itemlist=null;ListMapString,Object»list;final String[]str={,,A,B,,,,C,D,E,,,F};,/**Called whenthe activityis firstcreated.*/public voidonCreateBundle savedlnstanceState{super.onCreatesavedlnstanceState;setContentViewR.layout.main;itemlist=ListView findViewByldR.id.itemlist;refreshListltems;private voidrefreshListltems{list=buildListForSimpleAdapter;SimpleAdapter notes=new SimpleAdapterthis,list,R.layout.item,new String[]{str},new int[]{R.id.TextViewOlJ;itemlist.setAdapternotes;itemlist.setSelectionO;设置控件与否显示的属性设置属性android android:visibility此属性意思是此视图与否显示,例如中其有三个属性显示;显示黑RelativeLayout android:visibility=goneH visibleinvisible背景条;不显示gone在类中,可以设置其显示与否,不显示setVisibilityView.GONE;显示setVisibilityView.VISIBLE;为了防止软键盘挡上输入框,可以试试设置或者activity android:windowSoftlnputMode=stateVisible|adjustResize activityandroid:windowSoftlnputMode=stateVisible|adjustPan设置控件的宽高,用措施setlayoutparams做应用时,也许会需要动态变化控件的背景图片,假如仅仅是简朴的点击,选中之类的事件,假如靠程序中写监听的代码就显得太麻烦了,在这种状况下,你可以使用动态变化控件背景selector>在目录下建一种文献,根据需要,不一样的状态下建立不一样的并对应对应1res/drawable handlebackground.xml item,的图片xml version=
1.0encoding=UTF-8selector xmlns:android=,,item android:state_pressed=trueandroid:drawable=@drawable/pressed_application_background_static”/item android:state_focused=true android:state_enabled=trueandroid:state_window_focused=Htrueandroid:drawable=,,@drawable/focused_application_background_static/itemandroid:drawable=@android:color/transparent//selector、在构造是引用这个2layout xmllmageButtonandroid:id=,,@+id/imagebuttonandroid:layout_width=wrap_contentandroid:layout__height=wrap_contentandroid:src=@drawable/normalbackgroundandroid:background=@drawable/handlebackground/lmageButton为你要显示的前景图片normalbackground.png为点击时的背景(系统默认为淡黄色)pressed_application_background_static.png为焦点停留时的背景(系统默认为橙色)focused_application_background_static.png获得的版本,并设置动画效果androidsdk privateListMapString Object»buildListForSimpleAdapter{ListMapString/zObject»list=new ArrayListMapString,Object»2;//Build amap for the attributesMapString,Object map=new HashMapString,Object;,呵呵呵呵呵叩map.putstr”list.addmap;map=new HashMapString,Object;呵呵;map.putCstr,list.addmap;map=new HashMapString,Object;,呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵”;map.putstr”list.addmap;map=new HashMapString,Object;,呵呵呵呵呵呵map.put”str“”list.addmap;map=new HashMapString,Object;,呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵”;map.putstr”\n\n\n list.addmap;map=new HashMapString,Object;・”呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵”;map putstr,\n list.addmap;return list;}创立快捷方式public staticvoid addShortcutContextcontext{String ACTION_INSTALL_SHORTCUT=com.android.launcher.action.lNSTALL_SHORTCUT;〃快捷方式要启动的包Intent intent=gotoWherecontext;〃设置快捷方式的参数Intent shortcutintent=new lntentACTION_INSTALL_SHORTCUT;〃设置名称shortcutintent.putExtralntent.EXTRA_SHORTCUT_NAME,context.getResources设置启动.getStringR.string.wap;//Intentshortcutintent.putExtralntent.EXTRA_SHORTCUT_INTEN-C intent;〃设置图标shortcutlntent.putExtralntent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutlconResource.fromContextcontext,R.drawable.icon;〃只创立一次快捷方式shortcutintent.putExtraCduplicate,false;//创立context.sendBroadcastshortcutlntent;我的经验是最内层用实现非均等分割,外层用wrap_content fill_parent有人告诉我这样整将子的我试了,很好用LinearLayout android:layout_height=Odip通过程序挂断电话代码iTelephony=ITelephony getlTelephonyMethod.invoketelMgr,Object[]null;iTelephony.endCall;屏幕有关单位解释Android设备独立像素.不一样设备有不一样的显示效果,这个和设备硬件有关,一般我们为了支dip:device independentpixels持、和推荐使用这个,不依赖像素WVGA HVGAQVGA像素.不一样设备显示效果相似,一般我们代表像素,这个用的比较多px:pixels HVGA320x480是一种原则的长度单位,英寸,用于印刷业,非常简朴易用;pt:point,lpt=l/72放大像素.重要用于字体显示sp:scaled pixelsbest fortextsizeo中可现实图片和文字混排效果Textviewfinal TextViewtextview=TextViewfindViewByldR.id.dietJogJabel;final DrawableiconDrawable=getResources.getDrawableR.drawable.icon;textView.setCompoundDrawablesWithlntrinsicBoundsiconDrawable,iconDrawable,iconDrawable,iconDrawable;使用时所占比重与所用的方式有关LinearLayout Layout_weight Layout_height内部的用值越大占的空间越小,LinearLayout LinearLayoutfill_parent,layout_weight内的控件用值越大占的空间越大LinearLayout wrap_content,layout_weight自定义控件一般指的自绘控件,最简朴的形式就是继承然后在措施里面使用画布进行绘制其实最佳View,onDraw Canvas是继承等这样的已经有组建,防止自定义组建影响布局ImageView TextView自定义控件重要覆盖两个措施和onDraw ontouch为了到达一种对称的效果右边的血条要从左往右减少今天尝试做个类似街霸中的游戏场景,头部需要显示双方的血条PK展现血条首先想到的是使用发现都是从右往左减少ProgressBar了下没发既有资料简介怎样配置来实现从左到右变化的效果google丰衣足食,遍万幸的是我们可以看到源码那么自己动手
一、失的尝试来做镜像处理首先想到的是使用Matrix将中的源码建一种自己的进度条ProgressBar copyMyProgressBar当然,这中间要处理诸多错误信息需要定义自己的进度条可配置的属性,样式等等修改中的ProgressBar onDraw措施
1.[color=Red]二
2.Matrix mnew Matrix;
3.m.setScale-1,1;
4.m.postTranslate d.getMinimumWidthO+getPaddingLeft,getPaddingTop;
5.canvas.setMatrixm;
6.[/color]
7.d.draw canvas;复制代码红色部分为我添加的内容跑起来后发现中存在和不一样状况下会影响布局progressBar MinWidthMaxWidth,无奈下只能跟代码了
二、成功的尝试这次跟进了
1.d.draw canvas;复制代码这行代码,发现在构造的时候使用了阅读下文档发下如下简介progressBar ClipDrawable.android:clipOrientation Theorientationfortheclip,android:gravity Specifieswhere toclip withinthe drawable.翻译过来就是定义裁剪的方向(水平方向裁剪还是垂直方向裁剪)android:cl ipOrientation指定中可裁剪的部分android:gravity drawable尝试修改了下的配置文献progressBar Drawable
2.layer-listxmlns:android=,z,,
3.item android:id=,,@android:id/backgroundz/
4.shape
5.cornersandroid:radius=,,5dip,//gradient
5.android:startColor=,/#ff9d9e9d,/
6.android:centerColor=z/#ff5a5d5az/
7.android:centerY=zz
0.75〃
8.android:endColor=,/#ff747674z,
9.〃〃android:angle=
27010.
11./
12./shape
14.item android:id=,z@android:id/secondaryProgress,z
15.[color=Red]
16.clipandroid:gravity=z,right,z
17.[/color]
18.shape
19.cornersandroid:radius=,,5dip,z/
20.gradient
21.
22.
29./clip
23.
30./item
24.android:startColor=,/#80ffd300z/
25.android:centerColor=//#80ffb600z/
26.android:centerY=z,
0.75〃
27./android:endColor=,,#a0ffcb00/z
28./shape〃〃android:angle=
27031.
32.item android:id=z,@android:id/progress,z
33.[color=Red]〉
34.clip android:gravity=right”
35.[/color]
36.shape
37.corners android:radius=/,5dip/z/
38.gradient
39.android:startColor=/,#ffffd300,z
40.android:centerColor=/z#ffffb600/z
41.android:centerY=z/
0.75〃
42.android:endColor=z,#ffffcbOO/z
43.〃〃android:angle=
27044./
45./shape
46./clip
47.
48./layer-list复制代码同步定义进度条的样式:
1.〃二〃〃?xml version=l.0encoding utf-
82.resources
3.stylename=//myProgressBarStyle,,
4.itemname=/,indeterminateOnly,/false/item
5.itemname=//progressDrawable,,@drawable/progress_horizental/item
6.item name=/,minHeight//12dip/item
7.item namez,maxHeight,z12dip/item,,=
8.item nameminWidth/,100dip/item z,=
9.item namemaxWidth/z150dip/item二
10./style
11./resources复制代码运行的效果控件的样式,是条在屏幕的下方,而内容部分在屏幕上方TabWidget tab是整个的容器,包括两部分,和就是每个的标签,TabHostTabTabWidget FrameLayoutTabWidget tabo则是内容FrameLayout tab假如我们使用如同必须设置为extends TabAcitivty,ListActivity,TabHost@android:id/tabhost、必须设置为2TabWidget android:id@android:id/tabs
3、FrameLayout需要设置android:id为©android:id/tabcontent、参照这4先自定义一种文献:xml〃・〃二
1.xmlversion=10encoding
2.TabHost xmlns:android=〃函〃
3.android:id=ndroid:id/tabhost
4.android:layout_width=〃f i1l_parentz/
5.android:layoutheight=,,fi1l_parentz,
6.LinearLayout
7.android:orientation=vertical”
8.android:layout_width=,zfill_parentz,
9.android:layout_height=/zfill_parent/z
10.FrameLayout
11.android:id=zz@android:id/tabcontent
12.android:layout_width=/zfi1l_parentz,
13.android:layout_height=,,fi1l_parentz,
14.〃android:layout weight=
1.
015.
16.android:paddingBottom=//53px/z/
17.TabWidget
18.android:id=z,©android:id/tabs,z
19.二〃android:layout_alignParentBottom true”
20.android:layoutwidth=zfill_parentz,
21.〃〃android:layout height=50px
22.android:vi sibility=/,gone,,
23.android:layout_weight=//
0.0〃/
24.
25.RadioGroupandroid:gravity=centejvertical”
26.androi d:i d=〃@+i d/mai nradiandroid:orientation=horizontal”
27.andro i d:background=〃@drawab1e/rad iogroup_background,z
28.android:layout_width=,fill_parent,z
29.〃〃android:layout height=50dip
30.二〃android:layout gravitybottonT
31.RadioButton〃〃
32.android:id=@+id/main_index_button
33.android:layout_marginTop=/,l.Odip”
34.android:layout_marginRight=,/5dip/z
35.android:text=z,@string/main_namez,
36.andro i d:drawab1eTop=,,@drawab le/unistall
37.style=z/@style/main_tab_bottom/,〃〃
38.android:background=@drawab1e/radi0bg/
39.RadioButton
40.androi d:id=〃@+id/ma in_running_button”android:
41.layout_marginTop=zl.Odip〃android:layout
42.〃〃,marginRight=5dip android:text=
43.z@string/run_manager_nanie/,
44.android:drawab1eTop=〃@drawable/unistalT
745.style=z/@style/main_tab_bottom,z
46.android:background=,,@drawab1e/radiobg〃/
47.RadioButton
48.android:id=,z@+id/main_uninstall_button/,android:
49.layout_marginTop=,zl.Odip〃android:text=/,
50.@string/uninstall managername”
51.andro id:drawab1eTop=/,©drawab le/unistalT/
52.〃style=@style/main_tab_bottonT
53.android:background=,z@drawable/radio_bg,z/
54./RadioGroup
55./LinearLayout
56./TabHost复制代码为了让显示在下方,要将的设置为再将的设置为tabHost RadioGrouplayout gravitybottom,FrameLayout layoutweight1,这样就可以将撑到最下方〃里面定义了样式文献RadioGroup style=@style/main_tab_bottom接下来就是在中初始化并添加activity tabhost
1.tabHost=TabHost findViewByldandroid.R.id.tabhost;〃〃
2.tabHost.addTabConstant.tabHost.newTabSpec Main
3..setindicatorgetStringR.string.main_name,null
4..setContentnew Intentthis,Main,class;
5.tabHost.addTabConstant.tabHost.newTabSpecRunManager
6..setindicator getStringR.string.run_manager_name,null
7..setContentnew Intentthis,RunManager.class;
8.tabHost.addTab Constant.tabHost.newTabSpec,,UninstallManager,/
9..setindicator getStringR.string.uninsta1l_manager_name,null
10..setContentnew Intentthis,UninstallManager.class;复制代码初始化每个并为其添加事件,当点击对应的时就可以通过RadioButton setOnCheckedChangeListenerRadioButton措施显示到目前页面setCurrentTabByTagO
2.RadioButton findViewByldR.id.main_index_button
3.,setOnCheckedChangeListener this;
4.RadioButton findViewByldR.id.main runningbutton
5..setOnCheckedChangeListener this;
6.RadioButton findViewByldR.id.main_uninstall_button
7..setOnCheckedChangeListenerthis;
8.}
9.
10.©Override
1.private voidinitRadios{
11.public voidonCheckedChangedCompoundButton buttonView,boolean isChecked{
12.ifisChecked{
13.switch buttonView.getldO{
14.case R.id.main indexbutton:
15.tabHost.setCurrentTabByTagz,Main,z;
16.break;
17.case R.id.main_running_button:
18.tabHost.setCurrentTabByTag z/RunManagerz/;
19.break;
20.case R.id.main uninstallbutton:
21.tabHost.setCurrentTabByTagz,UninstalIManager,z;
22.break;
23.
24.
25.在■等事件中,可以根据OnClickListener Listener措施来判断是哪个控件被选中了View.getld去掉边白措施Dialog使用样式文献,在目录下新建文献,编写如下代码values styles.xmlresources〉n nnstyle name=dialog parent=@android:style/Theme.Dialognitem name=android:windowFrame@null/itemn nitemname=android:windowlsFloating true/itemnitem name=android:windowlsTranslucentfalse/itemH nitemname=android:windowNoTitle true/itemnitem name=android:background@android:color/black/itemn nitemname=android:windowBackground@null/itemnitem name=android:backgroundDimEnabledfalse/item/style/resources调用时,使用的接口类,接口编写如下代码AlerDialog DialogDialogdialog=new DialogSetActivity.this R.style.dialog;zdialog.setContentviewR.layout.test;dialog.show;下面我们查看一下的源码文献,里面的构造函数为如下:Dialogpublic DialogContextcontext,int theme{mContext=new ContextThemeWrappercontext,theme==0com.android.internal.R.style.Theme_Dialog:theme;mWindowManager=WindowManagercontext.getSystemServicewindow;Window w=PolicyManager.makeNewWindowmContext;mWindow=w;w.setCallbackthis;w.setWindowManagermWindowManager,null,null;w.setGravityGravity.CENTER;mUiThread=Thread.currentThread;mDismissCancelHandler=new DismissCancelHandlerthis;这里面我们可以看出,使用了默认的构造函数为设置样式,假如没有为其设置样式,即默认加载事先编写Android Dialog好的样式文献,一共由多种的图片构成,大部分都是带有边框的图片,因此就是为何我们上边的样式Dialog
9.png
9.png文献要将其背景清除掉这个东西搞了我很久,但愿对你有协助前后效果对比未设置前:设置后:Efalse模土”获得手机上网的Android3G IPpublicString getLocalIpAddress{try{for EnumerationNetworkInterfaceen=NetworkInterface.getNetworkInterfaces;en.hasMoreElements;{Networkinterface intf=en.nextElement;For EnumerationInetAddressenumlpAddr=intf.getlnetAddresses;enumIpAddr.hasMoreElements;{InetAddress inetAddress=enumlpAddr.nextElement;if!inetAddress.isLoopbackAddress{return inetAddress.getHostAddress,toString;}catch SocketExceptionex{Log.eLOG_TAG,ex.toString;}return null;}在代码中让顾客输入无效EditTexteditLicenseNo.setFiltersnew InputFilter[]{new InputFilter{@Override publicCharSequencefilterCharSequence source,int start,int end,Spanned dest,int dstart,int dend{return source.length1dost.subSequencedstart,dend:!!If•}};int version=Integer.valueOfandroid.os.Build.VERSION.SDK;if version=5{〃此为自定义的动画效果,下面两个为系统的overridePendingTransitionR.anim.zoomin,R.anim.zoomout;两个自定义的动画效果文献,寄存位置为XML res/anim/动画进入效果1,zoomin.xmlxml version=
1.0encoding=utf-8set xmlns:android=”android:interpolator=@android:anim/decelerate_interpolator scaleandroid:fromXScale=
2.0android:toXScale=
1.0android:fromYScale=
2.0android:toYScale=
1.0android:pivotX=50%p android:pivotY=50%pandroid:duration=@android:integer/config_mediumAnimTime”//set复制代码动画退出效果:2,zoomout.xmlxml version=
1.0encoding=utf-8set xmlns:android=,,,,android:interpolator=@android:anim/decelerate_interpolatorandroid:zAdjustment=top scaleandroid:fromXScale=
1.0android:toXScale=.5android:fromYScale=
1.0android:toYScale=.5android:pivotX=50%p android:pivotY=50%pandroid:duration=@android:integer/config_mediumAnimTime/alpha android:fromAlpha=
1.0android:toAlpha=0android:duration=,,@android:integer/config_mediumAnimTime//set获得控件在屏幕或窗口内的坐标int[]location=new int
[2];〃获取在目前窗口内的绝对坐标view.getLocationlnWindowlocation;〃获取在整个屏幕内的绝对坐标view.getLocationOnScreenlocation;坐标坐标location
[0]—x,location控件对齐那点事属性是对该内容的限定.例如一种上面的你可以设置该在的靠左,靠右等位置.android:gravity view button text.text view该属性就干了这个.是用来设置该相对与起父的位置.例如一种在里,你想把该放在android:layout_gravity viewviewbuttonlinearlayout button靠左靠右等位置就可以通过该属性设置.几种的使用阐明Menu
1.Options Menu.通过按下手机上的键,可以打开最多只能在屏幕最下面显示个菜单项,称为MENU Options Menuo Options Menu6Icon.假如添加了多于个的菜单项,将通过菜单项显示,这种称为.当第一次被打开Menu6More”Expanded MenuOptions Menu时,系统将调用的措施,在这个措施中可以通过配置一种文献,或者调Activity onCreateOptionsMenuMenu menu XML用的措施来添加你想要的的措施将返回一种对象,你用通过这个对象来配置某Menu addMenu Menu add Menuitem些其他属性例如的措施诸多,要注意的是这个参数,它的唯一性icon,shortcut,intento Menuadd itemld当选择了一种时,会调用措施假如想修改需要重写OptionsMenuonOptionsltemSelectedMenultem itemOptionsMenu,措施onPrepareOptionsMenu方式一,用添加add/*Creates themenu items*/public booleanonCreateOptionsMenuMenu menu{menu.add0,MENU_NEW_GAME,0,New Game;menu.add0,MENU_QUI-C0,,,Quit.setlconR.drawable.menu_quit_icon;return true;/*Handles itemselections*/public booleanonOptionsltemSelected MenuItem item{switch item.getltemld{case MENU_NEW_GAME:newGame;return true;case MENU_QUIT:quit;return true;}return false;方式二,通过文献添加XML在下新建文献res/menu/options_menu.xml代码Xmlmenu xmlns:android=nitem android:id=H@+id/new_gameandroid:title=New Game/item android:id=@+id/quitandroid:title=Quit,//menu在措施中,我们这样写onCreateOptionsMenu代码Javapublic booleanonCreateOptionsMenuMenu menu{Menulnflater inflater=getMenulnflater;inflater.inflateR.menu.options_menu,menu;return true;
2.Context Menu.它需要注册到某个对象上,当长按这个大概秒时间,会出现这个为某个注册View View2Context MenuoView Context Menu是用措施来实现在显示前都会调用来生成registerForContextMenuView viewContext MenuonCreateContextMenu menu用来处理选中的菜单项onContextltemSelected注意:不支持和Context Menuicons shortcutkeys.代码Javapublic voidonCreateContextMenuContextMenu menu,Viewv,ContextMenuInfo menuinfo{super.onCreateContextMenumenu,v,menuinfo;menu.add0,EDITJD,0,Edit;menu.add0,DELETEJD,0,Delete;public booleanonContextltemSelectedMenultem item{AdapterContextMenu Infoinfo=AdapterContextMenuInfo item.getMenulnfo;switch item.getltemldO{case EDIT_ID:editNoteinfo.id;return true;case DELETEID:deleteNoteinfo.id;return true;default:return super.onContextltemSelecteditem;注册这个Context Menu:registerForContextMenugetListView;这里的是的措施,它将返回一种记住任何一种对象都可以注册一种getListView ListActivityListView.View ContextMenuo
3.Submenuspublic booleanonCreateOptionsMenuMenumenu{boolean result=super.onCreateOptionsMenumenu;SubMenu=menu.addSubMenuCFile;SubMenu editMenu=menu.addSubMenuCEdit;」;0,NEW D,0Jnew“」;0,OPEN DQJopen“©SAVJDQJsave;editMenu.add0,UNDO_ID,0,undo;editMenu.add0,REDO_ID,0Jredo;return result;
4.Menu Features菜单项分组的功能Menu groups在用的措施时,通过参数的设置可以实现分组用来显示或者隐藏你的菜单组Menuaddgroupld setGroupVisible用来启用或者禁用你的菜单组用来设置你的菜单项与否可选setGroupEnabled setGroupCheckablesetGroupCheckable措施有三个参数第一种参数是要设置的组,第二个参数与否可选,第三int group,boolean checkable,boolean exclusiveo个参数为表达单项选择,表达多选true false快捷键Shortcut keys我们还可以设置快捷键使用以设置字符,数setAlphabeticShortcutchar,setNumericShortcutint,setShortcutchar,int nJ字,组合字符+数字键注意不能添加紧捷键ContextMenu点击查看活动规则及其子类,当字符内容太长显示不下时可以省略号替代未显示的字符;省略号可以在显示TextView区域的起始,中间,结束位置,或者以跑马灯的方式显示文字的状态为被选中textview其实现只需在中对的属性做对应的设置即可xml textviewellipsize省略号在开头android:ellipsize=start省略号在中间android:ellipsize=,middle省略号在结尾android:ellipsize=end跑马灯显示android:ellipsize=marquee设置的前面的图片,可定制的呵呵RadioButtonRadioGroupandroid:layout_width=match_parent,,android:layout_height=Hwrap_content android:orientation=verticalandroid:checkedButton=@+id/lunch android:id=,,@+id/menuRadioButtonandroid:text=H@string/radio_group_l_breakfast android:id=@+id/breakfast己找一种图片就可以/android:button=@nuir7/B是可以自己定义的显示的,我给的例子就不显示的分割线可以变化颜色RadioButton buttonbutton androidlistviewListViewandroid:id=@+id/android:listandroid:layout_width=wrap_content android:layout_height=,,wrap_content android:divider=,,#FFCCOOandroid:dividerHeight=,,4px/保持屏幕唤醒状态措施权限1:use PowerManagerand WakeLockAndroidManifest.xml程序中的代码uses-permission android:name=android.permission.WAKE_LOCK/PowerManager pm=PowerManager getSystemServiceContext.POWER_SERVICE;PowerManager.WakeLock mWakeLock=pm.newWakeLockPowerManager.SCREEN_DIM_WAKE_LOCK,My Tag;//in onResumecall mWakeLock.acquire;//in onPausecall mWakeLock.release;措施把下面的代码加入到程序措施中:2:use thewindow flagFLAG_KEEP_SCREEN_ON onCreate@Overrideprotected voidonCreateBundle icicle{super.onCreateicicle;//Set keepscreen ongetWindow.addFlagsWindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;提醒顾客输入有问题直接上代码Animation animation=Animationlltils.loadAnimationthis,R.anim.shake;EditText editText=EditText findViewByldR.id.edittext;editText.startAnimationanimation;里面面的是表达轴方向的移动距离fromXDelta,toXDelta xshake.xml:〈translate xmlns:android=android:fromXDelta=0android:toXDelta=30android:duration=1000android:interpolator=@anim/cyclejnterpolator/文献cyclelnterpolator.xmlcyclelnterpolator xmlns:android=android:cycles=,,3,,/抖动次3动态设置背景色TextViewet.setBackgroundResourceR.color.white;防止滚动的时候背景闪烁,需加上ListView androidcacheColorHint=#00000000假如设置了的listview android:background=@drawable/background就要加上android:cacheColorHint=#00000000通过添加一种为的当里面没有的时候,就会显示的内容id android:empty TextView,ListView dataTextViewxml version=
1.0encoding=utf-8LinearLayout xmlns:android=android:layout_width=wrap_contentandroid:layout_height=wrap_contentListView android:id=@id/android:listandroid:layout_width=fill_parentandroid:layout_height=fill_parent/TextView android:id=,,@id/android:emptyandroid:layout_width=wrap_content二”对不起,没有数据显示”/〉android:layout_height=wrap_content ardroid:text/LinearLayout需要注意的是,的使用的是,,即系统默认的而紧接其后的使用的也是系统默认ListView id,@id/android:list”id,TextView,id的,BP,,@id/android:emptyo自定义控件单行文本跑马灯控件import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.os.Parcel;import android.os.Parcelable;import android.util.AttributeSet;import android.view.Display;import android.view.View;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.TextView;/***〃***单行文本跑马灯控件*TODO*@author tianlu下午©version
1.0*Create At:-2-1609:35:03*/public classAutoScrollTextView extendsTextView implementsOnClickListener{public finalstatic StringTAG=AutoScrollTextView.class.getSimpleName;〃文本长度private floattextLength=Of;private floatviewWidth=Of;〃文字的横坐标private floatstep=Of;〃文字的纵坐标private floaty=Of;〃用于计算的临时变量private floattemp_view_pIus_text_length=
0.0f;〃用于计算的临时变量private floattemp_view_pIus_two_text_length=
0.0f;〃与否开始滚动public booleanisStarting=false;〃绘图样式private Paintpaint=null;〃文本内容private Stringtext=public AutoScrollTextViewContextcontext{supercontext;initView;}public AutoScrollTextViewContextcontext,AttributeSet attrs{supercontext,attrs;initView;}public AutoScrollTextViewContextcontext,AttributeSet attrs,int defStyle{supercontext,attrs,defStyle;initView;}/***〃***初始化控件*/。
个人认证
优秀文档
获得点赞 0