当前位置:  编程技术>移动开发
本页文章导读:
    ▪EditText获得焦点时的背景怎么修改        EditText获得焦点时的背景如何修改 EditText有一个background属性(对应setBackgroundResource方法),可以修改EditText的背景颜色但是在获得焦点的时候,想让它的背景颜色和未获得焦点时的不一样.........
    ▪ 运用Intent及Uri启动常用的应用与服务        使用Intent及Uri启动常用的应用与服务 一些在Android中常用的Intent启动服务,当执行startActivity时候,Android将会根据Intent绑定的信息寻找最合适的启动程序来接应,并执行程序以完成意图的实现.........
    ▪ Native Activity讲授       Native Activity讲解 NativeActivity前提条件1. Android 2.3 SDK is required2. Android NDK r5 or later version is required3. For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not .........

[1]EditText获得焦点时的背景怎么修改
    来源: 互联网  发布时间: 2014-02-18
EditText获得焦点时的背景如何修改
EditText有一个background属性(对应setBackgroundResource方法),可以修改EditText的背景颜色
但是在获得焦点的时候,想让它的背景颜色和未获得焦点时的不一样,怎样修改它的属性呢。
可以参考如下代码:

EditText editText = (EditText) findViewById(R.id.search_text);		
//给editText增加获得焦点的响应
editText.setOnFocusChangeListener(new OnFocusChangeListener(){
	@Override
	public void onFocusChange(View v, boolean hasFocus){
		if(hasFocus){
                       //获得焦点时,修改背景属性
                       //R.drawable.edit_text_bg_focus为背景资源
			v.setBackgroundResource(R.drawable.edit_text_bg_focus);
		}
		else{
			v.setBackgroundResource(R.drawable.edit_text_bg_unfocus);
		}
	}
});


这样就可以修改editText在获得焦点时的背景属性了。

    
[2] 运用Intent及Uri启动常用的应用与服务
    来源: 互联网  发布时间: 2014-02-18
使用Intent及Uri启动常用的应用与服务
一些在Android中常用的Intent启动服务,当执行startActivity时候,Android将会根据Intent绑定的信息寻找最合适的启动程序来接应,并执行程序以完成意图的实现。

打开浏览器显示网页:
Uri uri = Uri.parse("http://www.ataaw.com");
Intent intent  = new Intent(Intent.ACTION_VIEW,uri);
startActivintenty(intent);

由地图参数显示地图:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent intent = new Intent(Intent.Action_VIEW,uri);
startActivintenty(intent);

拨打电话,调用拨号程序:
Uri uri = Uri.parse("tel:13800138000");
Intent intent = new Intent(Intent.ACTION_DIAL, uri); 
startActivintenty(intent); 

调用发送短信的程序发送SMS/MMS
Intent intent = new Intent(Intent.ACTION_VIEW);  
intent.putExtra("sms_body", "ATAAW.COM");  
intent.setType("vnd.android-dir/mms-sms");  
startActivintenty(intent); 

调用短信程序发送短信
Uri uri = Uri.parse("smsto:13800138000");  
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);  
intent.putExtra("sms_body", "ATAAW.COM");  
startActivintenty(intent); 

调用彩信服务发送彩信
Uri uri = Uri.parse("content://media/external/images/media/exp");  
Intent intent = new Intent(Intent.ACTION_SEND);  
intent.putExtra("sms_body", "ATAAW.COM");  
intent.putExtra(Intent.EXTRA_STREAM, uri);  
intent.setType("image/png");  
startActivintenty(intent);

启动邮件应用程序发送Email
Uri uri = Uri.parse("mailto:ataaw.com@gmail.com");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivintenty(intent);

Intent intent = new Intent(Intent.ACTION_SEND);  
intent.putExtra(Intent.EXTRA_EMAIL, "android.sz@live.com");  
intent.putExtra(Intent.EXTRA_TEXT, "邮件内容。");  
intent.setType("text/plain");  
startActivintenty(Intent.createChooser(intent, "Choose Email Client")); 

Intent intent=new Intent(Intent.ACTION_SEND);    
String[] tos={"ataaw.com@gmail.com"};    
String[] ccs={"cc@ataaw.com"};    
intent.putExtra(Intent.EXTRA_EMAIL, tos);    
intent.putExtra(Intent.EXTRA_CC, ccs);    
intent.putExtra(Intent.EXTRA_TEXT, "邮件内容。");    
intent.putExtra(Intent.EXTRA_SUBJECT, "邮件主题");    
intent.setType("message/rfc822");    
startActivintenty(Intent.createChooser(intent, "Choose Email Client"));  

添加邮件附件内容
Intent intent = new Intent(Intent.ACTION_SEND);  
intent.putExtra(Intent.EXTRA_SUBJECT, "主题");  
intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/ataaw.mp3");  
sendIntent.setType("audio/mp3");  
startActivintenty(Intent.createChooser(intent, "Choose Email Client"));

播放mp4多媒体文件
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/ataaw.mp3");
intent.setDataAndType(uri, "audio/mp3");
startActivintenty(intent);

1 楼 cention 2011-10-07  
村口督屎,做android啊
2 楼 cention 2011-10-07  
行情好不好
3 楼 fox6900141 2012-03-20  
cention 写道
村口督屎,做android啊
认识???

    
[3] Native Activity讲授
    来源: 互联网  发布时间: 2014-02-18
Native Activity讲解
NativeActivity
前提条件
1. Android 2.3 SDK is required
2. Android NDK r5 or later version is required
3. For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
4. A recent version of awk (either GNU Awk or Nawk) is also required.
5. For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin 1.5 installations.

配置文件
AndroidManifest.xml文件中声明Activity
<activity android:name="android.app.NativeActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden">
     <!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
                  android:value="native-activity" />
<intent-filter>
     <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

程序
以NDK samples中的native-activity为例,此samples使用NativeActivity,完成根据点击屏幕不同位置,变化屏幕颜色的功能。(灰色背景是native-activity中的代码)
1. NativeActivity的入口
/**
* This is the main entry point of a native application that is using
* android_native_app_glue.  It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state)

2. 需要在android_main函数中向注册state注册应用命令处理函数和输入事件处理函数
state->onAppCmd = engine_handle_cmd;
state->onInputEvent = engine_handle_input;
命令处理函数
// Fill this in with the function to process main app commands (APP_CMD_*)
void (*onAppCmd)(struct android_app* app, int32_t cmd);
可处理的命令如下:
enum {
    /**
     * Command from main thread: the AInputQueue has changed.  Upon processing
     * this command, android_app->inputQueue will be updated to the new queue
     * (or NULL).
     */
    APP_CMD_INPUT_CHANGED,

    /**
     * Command from main thread: a new ANativeWindow is ready for use.  Upon
     * receiving this command, android_app->window will contain the new window
     * surface.
     */
    APP_CMD_INIT_WINDOW,

    /**
     * Command from main thread: the existing ANativeWindow needs to be
     * terminated.  Upon receiving this command, android_app->window still
     * contains the existing window; after calling android_app_exec_cmd
     * it will be set to NULL.
     */
    APP_CMD_TERM_WINDOW,

    /**
     * Command from main thread: the current ANativeWindow has been resized.
     * Please redraw with its new size.
     */
    APP_CMD_WINDOW_RESIZED,

    /**
     * Command from main thread: the system needs that the current ANativeWindow
     * be redrawn.  You should redraw the window before handing this to
     * android_app_exec_cmd() in order to avoid transient drawing glitches.
     */
    APP_CMD_WINDOW_REDRAW_NEEDED,

    /**
     * Command from main thread: the content area of the window has changed,
     * such as from the soft input window being shown or hidden.  You can
     * find the new content rect in android_app::contentRect.
     */
    APP_CMD_CONTENT_RECT_CHANGED,

    /**
     * Command from main thread: the app's activity window has gained
     * input focus.
     */
    APP_CMD_GAINED_FOCUS,

    /**
     * Command from main thread: the app's activity window has lost
     * input focus.
     */
    APP_CMD_LOST_FOCUS,

    /**
     * Command from main thread: the current device configuration has changed.
     */
    APP_CMD_CONFIG_CHANGED,

    /**
     * Command from main thread: the system is running low on memory.
     * Try to reduce your memory use.
     */
    APP_CMD_LOW_MEMORY,

    /**
     * Command from main thread: the app's activity has been started.
     */
    APP_CMD_START,

    /**
     * Command from main thread: the app's activity has been resumed.
     */
    APP_CMD_RESUME,

    /**
     * Command from main thread: the app should generate a new saved state
     * for itself, to restore from later if needed.  If you have saved state,
     * allocate it with malloc and place it in android_app.savedState with
     * the size in android_app.savedStateSize.  The will be freed for you
     * later.
     */
    APP_CMD_SAVE_STATE,

    /**
     * Command from main thread: the app's activity has been paused.
     */
    APP_CMD_PAUSE,

    /**
     * Command from main thread: the app's activity has been stopped.
     */
    APP_CMD_STOP,

    /**
     * Command from main thread: the app's activity is being destroyed,
     * and waiting for the app thread to clean up and exit before proceeding.
     */
    APP_CMD_DESTROY,
};
输入事件处理函数
engine_handle_input函数里设置开始动画并且记录下点击屏幕的x和y的坐标。
engine->animating = 1;
engine->state.x = AMotionEvent_getX(event, 0);
engine->state.y = AMotionEvent_getY(event, 0);
// Fill this in with the function to process input events.  At this point
// the event has already been pre-dispatched, and it will be finished upon
// return.  Return 1 if you have handled the event, 0 for any default
// dispatching.
int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
使用AInputEvent_getType(event)方法判断是按键事件还是点击事件;
点击事件调用以下方法进一步处理
int32_t AMotionEvent_ xxx (const AInputEvent* motion_event);
按键事件调用以下方法进一步处理
int32_t AKeyEvent_xxx (const AInputEvent* key_event);
3. loop waiting for stuff to do
while (1) {
4. Waits for events to be available
while ((ident = ALooper_pollAll(engine.animating ? 0 : -1, NULL,
&events, (void**) &source)) >= 0) {
当engine.animating为0时,一直等待有事件发生,才返回
当engine.animating为1时,表示开始动画,这时ALooper_pollAll函数不阻塞直接返回。
/**
*If the timeout is zero, returns immediately without blocking.
* If the timeout is negative, waits indefinitely until an event appears.
* Returns a value >= 0 containing an identifier if its file descriptor has data
* and it has no callback function (requiring the caller here to handle it).
*/
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
5. Process this event
source->process(state, source);
6. 在屏幕填充颜色
engine_draw_frame(&engine)函数中调用
glClearColor(((float) engine->state.x) / engine->width,
engine->state.angle, ((float) engine->state.y) / engine->height, 1);向屏幕填充颜色,三个参数分别是red,green,blue。

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3