首页 文章 精选 留言 我的

精选列表

搜索[harmonyos开发],共10000篇文章
优秀的个人博客,低调大师

开发篇(Development)

目录 2. 软件工程 (Software Engineering) 2.1. Open Source and License 3. Trac 项目管理 3.1. Administration 3.1.1. General 3.1.2. Ticket System 3.1.3. Version Control 3.2. Wiki 3.3. Timeline 3.4. Roadmap 3.5. Ticket 4. Project directory 5. 版本控制及如何运作 5.1. 版本库布局 5.2. 策略 5.3. nightly version 5.4. rc1,rc2,rc4 5.5. 怎样写注释信息 5.5.1. Fixed Bug 5.5.2. Implemented 5.5.3. Add 6. 任务分配原则 7. 项目运作 8. 收集需求 9. 代码审查制度 9.1. Coding workflow 10. Release Notes 11. 版本发行 12. 每周例会 13. 编码风格 13.1. php 文件 13.1.1. 格式与 编码 13.1.2. 循环嵌套 13.1.3. 取出行尾的空格以及多余的换行符 13.1.4. php 标签 13.1.5. 头部注释 13.2. String 13.3. Database 13.3.1. 结果集使用注意事项 13.3.2. 索引 13.3.3. 缓存 Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a>comments powered by Disqus 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

优秀的个人博客,低调大师

Android应用开发—Intent组件详解

转载自:Android中Intent组件详解 Intent是不同组件之间相互通讯的纽带,封装了不同组件之间通讯的条件。 Intent本身是定义为一个类别(Class),一个Intent对象表达一个目的(Goal)或期望(Expectation),叙述其所期望的服务或动作、与动作有关的数据等。Android则根据此Intent对象之叙述,负责配对,找出相配的组件,然后将 Intent对象传递给所找到的组件,Android的媒婆任务就完成了。 在Google Doc中是这样描述Intent的(摘自Android中文翻译组) 当接收到ContentResolver发出的请求后,内容提供者被激活。而其它三种组件──activity、服务和广播接收器被一种叫做intent的异步消息所激活。intent是一个保存着消息内容的Intent对象。对于activity和服务来说,它指明了请求的操作名称以及作为操作对象的数据的URI和其它一些信息。比如说,它可以承载对一个activity 的请求,让它为用户显示一张图片,或者让用户编辑一些文本。而对于广播接收器而言,Intent对象指明了声明的行为。比如,它可以对所有感兴趣的对象声明照相按钮被按下。 对于每种组件来说,激活的方法是不同的: 通过传递一个Intent对象至Context.startActivity()或Activity.startActivityForResult()以载入(或指定新工作给)一个activity。相应的activity可以通过调用 getIntent() 方法来查看激活它的intent。Android通过调用activity的onNewIntent()方法来传递给它继发的intent。 一个activity经常启动了下一个。如果它期望它所启动的那个activity返回一个结果,它会以调用startActivityForResult()来取代startActivity()。比如说,如果它启动了另外一个activity以使用户挑选一张照片,它也许想知道哪张照片被选中了。结果将会被封装在一个Intent对象中,并传递给发出调用的activity的onActivityResult() 方法。 通过传递一个Intent对象至Context.startService()将启动一个服务(或给予正在运行的服务以一个新的指令)。Android调用服务的onStart()方法并将Intent对象传递给它。 与此类似,一个Intent可以被调用组件传递给 Context.bindService()以获取一个正在运行的目标服务的连接。这个服务会经由onBind() 方法的调用获取这个Intent对象(如果服务尚未启动,bindService()会先启动它)。比如说,一个activity可以连接至前述的音乐回放服务,并提供给用户一个可操作的(用户界面)以对回放进行控制。这个activity可以调用 bindService() 来建立连接,然后调用服务中定义的对象来影响回放。 应用程序可以凭借将Intent对象传递给 Context.sendBroadcast() ,Context.sendOrderedBroadcast(), 以及Context.sendStickyBroadcast()和其它类似方法来产生一个广播。Android会调用所有对此广播有兴趣的广播接收器的 onReceive()方法将intent传递给它们。 Intent对象包含的内容 在Intent类的Java源代码中定义了Intent相关内容的变量,如下: // Action private String mAction; // Data private Uri mData; private String mType; private String mPackage; // ComponentName private ComponentName mComponent; // Flag private int mFlags; // category private HashSet<String> mCategories; // extras private Bundle mExtras; componentName(组件名称),指定Intent的目标组件的类名称。组件名称是可选的,如果填写,Intent对象会发送给指定组件名称的组件,否则也可以通过其他Intent信息定位到适合的组件。组件名称是个ComponentName类型的对象。 用法: Intent intent = new Intent(); // 构造的参数为当前Context和目标组件的类路径名 ComponentName cn = new ComponentName(HelloActivity.this, "com.byread.activity.OtherActivity"); intent.setComponent(cn); startActivity(intent); 相当于以下常用方法: Intent intent = new Intent(); intent.setClass(HelloActivity.this, OtherActivity.class); startActivity(intent); Intent类中也包含一个初始化ComponentName的构造函数: public Intent(Context packageContext, Class<?> cls) { mComponent = new ComponentName(packageContext, cls); } action(动作), 指定Intent的执行动作,比如调用拨打电话组件。 public Intent(String action) { mAction = action; } data(数据),起到表示数据和数据MIME类型的作用。不同的action是和不同的data类型配套的,通过设置data的Uri来获得。 public Intent(String action, Uri uri) { mAction = action; mData = uri; } 比如调用拨打电话组件: Uri uri = Uri.parse("tel:10086"); // 参数分别为调用拨打电话组件的Action和获取Data数据的Uri Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent); category(类别),被执行动作的附加信息。例如应用的启动Activity在intent-filter中设置category。 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> extras(附加信息),为处理Intent组件提供附加的信息。可通过putXX()和getXX()方法存取信息;也可以通过创建Bundle对象,再通过putExtras()和getExtras()方法来存取。 flags(标记),指示Android如何启动目标Activity,设置方法为调用Intent的setFlags方法。常用的Flags参数有: FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_NO_HISTORY FLAG_ACTIVITY_SINGLE_TOP Intent的投递 显式方式:直接设置目标组件的ComponentName,用于一个应用内部的消息传递,比如启动另一个Activity或者一个services。 通过Intent的setComponent和setClass来制定目标组件的ComponentName。 隐式方式:ComponentName为空,用于调用其他应用中的组件。需要包含足够的信息,这样系统才能根据这些信息使用intent filter在所有的组件中过滤action、data或者category来匹配目标组件。可参考Android中Activity组件详解(5.Activity的Intent Filter) 如果Intent指明定了action,则目标组件的IntentFilter的action列表中就必须包含有这个action,否则不能匹配; 如果Intent没有提供type,系统将从data中得到数据类型。和action一样,目标组件的数据类型列表中必须包含Intent的数据类型,否则不能匹配; 如果Intent中的数据不是content: 类型的URI,而且Intent也没有明确指定它的type,将根据Intent中数据的scheme (比如 http: 或者mailto: ) 进行匹配。同上,Intent 的scheme必须出现在目标组件的scheme列表中; 如果Intent指定了一个或多个category,这些类别必须全部出现在组建的类别列表中。比如 Intent中包含了两个类别:LAUNCHER_CATEGORY 和 ALTERNATIVE_CATEGORY,解析得到的目标组件必须至少包含这两个类别。 Intent调用常见系统组件 // 调用浏览器 Uri webViewUri = Uri.parse("http://blog.csdn.net/zuolongsnail"); Intent intent = new Intent(Intent.ACTION_VIEW, webViewUri); // 调用地图 Uri mapUri = Uri.parse("geo:100,100"); Intent intent = new Intent(Intent.ACTION_VIEW, mapUri); // 播放mp3 Uri playUri = Uri.parse("file:///sdcard/test.mp3"); Intent intent = new Intent(Intent.ACTION_VIEW, playUri); intent.setDataAndType(playUri, "audio/mp3"); // 调用拨打电话 Uri dialUri = Uri.parse("tel:10086"); Intent intent = new Intent(Intent.ACTION_DIAL, dialUri); // 直接拨打电话,需要加上权限<uses-permission id="android.permission.CALL_PHONE" /> Uri callUri = Uri.parse("tel:10086"); Intent intent = new Intent(Intent.ACTION_CALL, callUri); // 调用发邮件(这里要事先配置好的系统Email,否则是调不出发邮件界面的) Uri emailUri = Uri.parse("mailto:zuolongsnail@163.com"); Intent intent = new Intent(Intent.ACTION_SENDTO, emailUri); // 直接发邮件 Intent intent = new Intent(Intent.ACTION_SEND); String[] tos = { "zuolongsnail@gmail.com" }; String[] ccs = { "zuolongsnail@163.com" }; intent.putExtra(Intent.EXTRA_EMAIL, tos); intent.putExtra(Intent.EXTRA_CC, ccs); intent.putExtra(Intent.EXTRA_TEXT, "the email text"); intent.putExtra(Intent.EXTRA_SUBJECT, "subject"); intent.setType("text/plain"); Intent.createChooser(intent, "Choose Email Client"); // 发短信 Intent intent = new Intent(Intent.ACTION_VIEW); intent.putExtra("sms_body", "the sms text"); intent.setType("vnd.android-dir/mms-sms"); // 直接发短信 Uri smsToUri = Uri.parse("smsto:10086"); Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); intent.putExtra("sms_body", "the sms text"); // 发彩信 Uri mmsUri = Uri.parse("content://media/external/images/media/23"); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra("sms_body", "the sms text"); intent.putExtra(Intent.EXTRA_STREAM, mmsUri); intent.setType("image/png"); // 卸载应用 Uri uninstallUri = Uri.fromParts("package", "com.app.test", null); Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri); // 安装应用 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("/sdcard/test.apk"), "application/vnd.android.package-archive"); // 在Android Market中查找应用 Uri uri = Uri.parse("market://search?q=愤怒的小鸟"); Intent intent = new Intent(Intent.ACTION_VIEW, uri);

优秀的个人博客,低调大师

iOS开发之多媒体播放

iOS sdk中提供了很多方便的方法来播放多媒体。本文将利用这些SDK做一个demo,来讲述一下如何使用它们来播放音频文件。 AudioToolbox framework 使用AudioToolbox framework。这个框架可以将比较短的声音注册到 system sound服务上。被注册到system sound服务上的声音称之为 system sounds。它必须满足下面几个条件。 1、播放的时间不能超过30秒 2、数据必须是 PCM或者IMA4流格式 3、必须被打包成下面三个格式之一:Core Audio Format (.caf), Waveform audio (.wav),或者 Audio Interchange File (.aiff) 声音文件必须放到设备的本地文件夹下面。通过AudioServicesCreateSystemSoundID方法注册这个声音文件,AudioServicesCreateSystemSoundID需要声音文件的url的CFURLRef对象。看下面注册代码: #import<AudioToolbox/AudioToolbox.h>@interface MediaPlayerViewController : UIViewController { IBOutlet UIButton *audioButton; SystemSoundID shortSound; } - (id)init { self = [super initWithNibName:@"MediaPlayerViewController" bundle:nil];if (self) {// Get the full path of Sound12.aif NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Sound12" ofType:@"aif"];// If this file is actually in the bundle...if (soundPath) {// Create a file URL with this path NSURL *soundURL = [NSURL fileURLWithPath:soundPath];// Register sound file located at that URL as a system sound OSStatus err = AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &shortSound);if (err != kAudioServicesNoError) NSLog(@"Could not load %@, error code: %d", soundURL, err); } }return self; } 这样就可以使用下面代码播放声音了: - (IBAction)playShortSound:(id)sender { AudioServicesPlaySystemSound(shortSound); } 使用下面代码,还加一个震动的效果: - (IBAction)playShortSound:(id)sender { AudioServicesPlaySystemSound(shortSound); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } AVFoundation framework 对于压缩过Audio文件,或者超过30秒的音频文件,可以使用AVAudioPlayer类。这个类定义在AVFoundation framework中。 下面我们使用这个类播放一个mp3的音频文件。首先要引入AVFoundation framework,然后MediaPlayerViewController.h中添加下面代码: #import<AVFoundation/AVFoundation.h>@interface MediaPlayerViewController : UIViewController <AVAudioPlayerDelegate> { IBOutlet UIButton *audioButton; SystemSoundID shortSound; AVAudioPlayer *audioPlayer; AVAudioPlayer类也是需要知道音频文件的路径,使用下面代码创建一个AVAudioPlayer实例: - (id)init { self = [super initWithNibName:@"MediaPlayerViewController" bundle:nil];if (self) { NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"Music" ofType:@"mp3"];if (musicPath) { NSURL *musicURL = [NSURL fileURLWithPath:musicPath]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil]; [audioPlayer setDelegate:self]; } NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Sound12" ofType:@"aif"]; 我们可以在一个button的点击事件中开始播放这个mp3文件,如: - (IBAction)playAudioFile:(id)sender {if ([audioPlayer isPlaying]) {// Stop playing audio and change text of button [audioPlayer stop]; [sender setTitle:@"Play Audio File" forState:UIControlStateNormal]; }else {// Start playing audio and change text of button so// user can tap to stop playback [audioPlayer play]; [sender setTitle:@"Stop Audio File" forState:UIControlStateNormal]; } } 这样运行我们的程序,就可以播放音乐了。 这个类对应的AVAudioPlayerDelegate有两个委托方法。一个是 audioPlayerDidFinishPlaying:successfully: 当音频播放完成之后触发。当播放完成之后,可以将播放按钮的文本重新回设置成:Play Audio File - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { [audioButton setTitle:@"Play Audio File" forState:UIControlStateNormal]; } 另一个是audioPlayerEndInterruption:,当程序被应用外部打断之后,重新回到应用程序的时候触发。在这里当回到此应用程序的时候,继续播放音乐。 - (void)audioPlayerEndInterruption:(AVAudioPlayer *)player { [audioPlayer play]; } MediaPlayer framework 播放电影文件: iOS sdk中可以使用MPMoviePlayerController来播放电影文件。但是在iOS设备上播放电影文件有严格的格式要求,只能播放下面两个格式的电影文件。 • H.264 (Baseline Profile Level 3.0) • MPEG-4 Part 2 video (Simple Profile) 幸运的是你可以先使用iTunes将文件转换成上面两个格式。 MPMoviePlayerController还可以播放互联网上的视频文件。但是建议你先将视频文件下载到本地,然后播放。如果你不这样做,iOS可能会拒绝播放很大的视频文件。 这个类定义在MediaPlayer framework中。在你的应用程序中,先添加这个引用,然后修改MediaPlayerViewController.h文件。 #import<MediaPlayer/MediaPlayer.h>@interface MediaPlayerViewController : UIViewController <AVAudioPlayerDelegate> { MPMoviePlayerController *moviePlayer; 下面我们使用这个类来播放一个.m4v 格式的视频文件。与前面的类似,需要一个url路径。 - (id)init { self = [super initWithNibName:@"MediaPlayerViewController" bundle:nil];if (self) { NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"Layers" ofType:@"m4v"];if (moviePath) { NSURL *movieURL = [NSURL fileURLWithPath:moviePath]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; } MPMoviePlayerController有一个视图来展示播放器控件,我们在viewDidLoad方法中,将这个播放器展示出来。 - (void)viewDidLoad { [[self view] addSubview:[moviePlayer view]];float halfHeight = [[self view] bounds].size.height /2.0;float width = [[self view] bounds].size.width; [[moviePlayer view] setFrame:CGRectMake(0, halfHeight, width, halfHeight)]; } 还有一个MPMoviePlayerViewController类,用于全屏播放视频文件,用法和MPMoviePlayerController一样。 MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; [viewController presentMoviePlayerViewControllerAnimated:playerViewController]; 我们在听音乐的时候,可以用iphone做其他的事情,这个时候需要播放器在后台也能运行,我们只需要在应用程序中做个简单的设置就行了。 1、在Info property list中加一个 Required background modes节点,它是一个数组,将第一项设置成设置App plays audio。 2、在播放mp3的代码中加入下面代码: if (musicPath) { NSURL *musicURL = [NSURL fileURLWithPath:musicPath]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil]; [audioPlayer setDelegate:self]; } 在后台运行的播放音乐的功能在模拟器中看不出来,只有在真机上看效果。 总结:本文通过例子详细讲解了iOS sdk中用于播放音频文件的类,文章后面有本文的代码提供下载。 代码:http://files.cnblogs.com/zhuqil/MediaPlayer.zip 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/23/2115021.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发之邮件发送代码

邮件发送功能是由MessageUI Framework提供的,这个框架是iPhone sdk中最简单的框。由一个类、一个视图控制器,一个protocol组成。 一、创建视图控制器: MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; mc.mailComposeDelegate = self ; 二、设置邮件主题: [mc setSubject:@"Hello, World!"]; 三、设置收件人,收件人有三种: 1、设置主收件人 [mc setToRecipients:[ NSArray arrayWithObjects:@ "zhuqi0@126.com" , "@dave@iphonedevbook.com" , nil ]; 2、设置cc [mc setCcRecipients:[NSArray arrayWithObject:@"zhuqil@163.com"]]; 3、设置bcc [mc setBccRecipients:[NSArray arrayWithObject:@"secret@gmail.com"]]; 四、设置邮件主体,有两种格式。 一种是纯文本 [mc setMessageBody:@"Watson!!!\n\nCome here, I need you!" isHTML:NO]; 一个是html格式 [mc setMessageBody:@ "<HTML><B>Hello, Joe!</B><BR/>What do you know?</HTML>" isHTML: YES ]; 五、添加附件 添加附件需要三个参数,一个是NSData类型的附件,一个是mimetype,一个附件的名称。 NSString *path = [[NSBundle mainBundle] pathForResource:@"blood_orange" ofType:@"png"]; NSData *data = [NSData dataWithContentsOfFile:path]; [mc addAttachmentData:data mimeType:@"image/png" fileName:@"blood_orange"]; 六、视图呈现 [self presentModalViewController:mc animated:YES]; [mc release]; 七、视图控制器的委托方法 邮件视图控制器的委托方法包含在MFMailComposeViewControllerDelegate中,无论用户是否发送或取消发送,不论系统是否能够发送邮件, 方法 mailComposeController:didFinishWithResult:error: gets called都会被调用。 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail send canceled..."); break; case MFMailComposeResultSaved: NSLog(@"Mail saved..."); break; case MFMailComposeResultSent: NSLog(@"Mail sent..."); break; case MFMailComposeResultFailed: NSLog(@"Mail send errored: %@...", [error localizedDescription]); break; default: break; } [self dismissModalViewControllerAnimated:YES]; } 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/21/2112816.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

mac os 配置Android开发环境

1.安装Eclipse 下载地址:http://www.eclipse.org/downloads/ 用uname-a看一下当前的系统内核是多少位的,选择相应的版本下载,解压完即完成了安装 2.安装SDK 下载地址:http://developer.android.com/sdk/index.html 下载之后解压,移动到一个比较合适的位置,一般放在用户目录下 3.安装ADT 下载地址:http://developer.android.com/sdk/installing/installing-adt.html 该页面中有一个表格,里面有具体的下载地址,下载之后不用解压 4.配置环境 现在要将SDK,ADT都集成到Eclipse中 在Eclipse->help->InstallNewSoftware中点击Add按钮,再点archive,然后选择下载好的ADT压缩包后确定。 在下方的列表中会出现Developmenttools等项目,勾选所有选项后,点next,等待安装完成即可。 在Eclipse->偏好设定->android中,在右侧的SDKLocation栏中浏览之前解压前移动后的SDK目录,点击OK即可. 选择菜单中的Eclipse->Window->AndroidSDKManager, 在左上角的Tools->Options中勾选上Forcehttps://...,然后close,再次打开AndroidSDKManager,这样就能顺利的下载更新列表了,选择new和update之后,点击install按钮,一路安装即可 本文转自 ustb80 51CTO博客,原文链接:http://blog.51cto.com/ustb80/1030996,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android开发实践:玩转EditText控件

Android的EditText控件是一个非常常用的控件,用得最多的地方就是做登录、注册页面了,它能为用户提供一个直观便捷的输入框。本文简单总结下EditText控件中比较常用的一些设置,并为每一种设置提供两种方式的实现,一种是在布局文件中实现,另一种是在程序中通过代码动态的设置。 1. 如何添加一个方框 在Android的Hololight主题下,EditText控件默认是只有一条底部的蓝色横线的,怎么给你的EditText添加一个方框呢? 【布局】: 设置 android:background 属性,给它一个长方形的白***片,或者自定义一个长方形的drawable文件即可。 例如: 1 android:background= "@drawable/shape_bg" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setBackgroundResource(R.drawable.shape_bg); 2. 如何设置字体大小、颜色、加粗 【布局】: 布局中的属性依次为 android:textSize,android:textColor,android:textStyle属性 例如: 1 2 3 android:padding="15sp" android:textSize="15sp" android:textStyle="bold" 【代码】: 1 2 3 4 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setTextSize( 15 ); mEditText.setTextColor(Color.BLACK); mEditText.setTypeface(Typeface.DEFAULT_BOLD); 3. 如何设置以密码的形式显示 【布局】: 设置 android:password 属性为 true 例如: 1 android:password="true" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 4. 如何禁止用户输入回车换行 【布局】: 设置 android:singleLine 属性为 true 例如: 1 android:singleLine="true" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setSingleLine(); 5. 如何设置没有输入时的提示信息 【布局】: 设置 android:hint 属性的值 例如: 1 android:hint="inputyourname" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setHint( "Inputyourname" ); 6. 如何在输入框的行首空几个字符 【布局】: 设置 android:paddingLeft 属性即可 例如: 1 android:paddingLeft="15sp" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setPadding( 15 , 0 , 0 , 0 ); 7. 如何限制输入的长度 【布局】: 设置 android:maxLength 属性的值即可 例如: 1 android:maxLength="10" 【代码】: 1 2 3 4 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); InputFilter[]filters= new InputFilter[ 1 ]; filters[ 0 ]= new InputFilter.LengthFilter( 10 ); mEditText.setFilters(filters); 8. 如何限制输入类型为:数字,电话号码,日期,时间 【布局】: 设置 android:inputType 属性可以指定 textPassword, phone, number, date,time 等类型 例如: 1 android:inputType="text" 【代码】: 1 2 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setInputType(InputType.TYPE_CLASS_TEXT); //InputType有很多种类型可以选择 9. 如何限制只能输入指定的字符 【布局】: 设置 android:digits 属性即可 例如: 1 android:digits="abcdef" 【代码】: 有两种方法可以实现: 方法一: 1 2 3 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); Stringdigits= "abcdef" ; mEditText.setKeyListener(DigitsKeyListener.getInstance(digits)); 方法二: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); InputFilter[]filters= new InputFilter[ 1 ]; filters[ 0 ]= new MyInputFilter( "abcdef" ); mEditText.setFilters(filters); public class MyInputFilter extends LoginFilter.UsernameFilterGeneric{ private StringmAllowedDigits; public PopInputFilter(Stringdigits){ mAllowedDigits=digits; } @Override public boolean isAllowed( char c){ if (mAllowedDigits.indexOf(c)!=- 1 ){ return true ; } return false ; } } 10. 让密码的输入字体大小与明文的字体一致 当你设置了android:password = "true" 属性后,你会发现,它的字体大小会跟没有设置password属性的EditText的大小不一致,因此,如果期望他们表现一致的话,可以通过代码如下设置: 1 2 3 EditTextmEditText=(EditText)findViewById(R.id.MyEditText); mEditText.setTypeface(Typeface.DEFAULT); mEditText.setTransformationMethod( new PasswordTransformationMethod()); 本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/ticktick/1333414,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android开发实践:布局的平分

从一个简单的任务入手,“如何在水平方向上一左一右均匀地放置两个Button”,有很多种方式可以实现这个功能,在此做一个简单的总结,顺便深入理解下有关gravity, layout_weight 等相关概念的原理和应用。 一、效果图 二、思考 RelativeLayout 和 LinearLayout 中分别如何左右放置button (1) 在RelativeLayout中放置 由于 RelativeLayout 内部的子控件都可以指定相对位置,因此很容易实现左右放置两个Button的任务,如下所示: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 < RelativeLayout android:layout_width = "match_parent" android:layout_height = "wrap_content" android:orientation = "horizontal" > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "LeftButton" android:layout_alignParentLeft = "true" /> < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "RightButton" android:layout_alignParentRight = "true" /> </ RelativeLayout > 效果如图所示: (2) 在LinearLayout中放置 由于LinearLayout是顺序排放所有的控件,如果希望两个button分开地位于一左一右,则必须在两个Button之间再加一个layout_weight为1.0的隐形view才能实现。示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 < LinearLayout android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_margin = "10dp" android:orientation = "horizontal" > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "LeftButton" /> < View android:layout_width = "0dp" android:layout_weight = "1.0" android:layout_height = "0dp" /> < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "RightButton" /> </ LinearLayout > 效果如图所示: 三、 在水平方向“均分”整个Layout 其实,对于LinearLayout而言,最简单地平分方式就是将子控件的layout_width属性值设置为0,同时layout_weight属性设置为1.0这样,所有的子控件就会自动均分整个LinearLayout ,例如: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 < LinearLayout android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_margin = "10dp" android:orientation = "horizontal" > < Button android:layout_width = "0dp" android:layout_height = "wrap_content" android:layout_weight = "1.0" android:text = "LeftButton" /> < Button android:layout_width = "0dp" android:layout_height = "wrap_content" android:layout_weight = "1.0" android:text = "Right" /> </ LinearLayout > 效果如图: 由图中效果可以看到,两个Button很好地一左一右平分了整个LinearLayout,但是由于Button的layout_width设置的是0dp,通过layout_weight来决定长度,因此Button都被横向拉长了,如果希望Button的layout_width设置为wrap_content,那该如何实现均分呢?其实,可以通过在Button外再包围一层LinearLayout来实现,示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 < LinearLayout android:layout_width = "match_parent" android:layout_height = "wrap_content" android:layout_margin = "10dp" android:orientation = "horizontal" > < LinearLayout android:layout_width = "0dp" android:layout_height = "wrap_content" android:layout_weight = "1.0" android:orientation = "horizontal" > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "LeftButton" android:layout_gravity = "center" /> </ LinearLayout > < LinearLayout android:layout_width = "0dp" android:layout_height = "wrap_content" android:layout_weight = "1.0" android:orientation = "horizontal" android:gravity = "center_horizontal" > < Button android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "RightButton" /> </ LinearLayout > </ LinearLayout > 这样地话,由两个Button外围的LinearLayout平分了整个水平的layout,两个button的大小采用wrap_content,也不会被拉伸,并且通过外围的LinearLayout的android:gravity属性实现了居中。 这里注意Button外围的LinearLayout的android:gravity属性,很关键,该属性决定其子控件在该控件中的位置。所以Button外围的LinearLayout设置了android:gravity="center",因此Button才能在该LinearLayout的正中央。 思考,如果给Button加一个android:gravity="right"的属性,会是什么效果呢? 答案: 会使得 Button 内部的文字向右靠齐,而不是在中央。 本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/ticktick/1321114,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册