当前位置:  编程技术>移动开发
本页文章导读:
    ▪Java压缩技术相干        Java压缩技术相关 http://snowolf.iteye.com/blog/465433 ......
    ▪ TextView小组件的应用-附带超链接和跑马灯效果        TextView小组件的使用--附带超链接和跑马灯效果 一:新建HelloTextView 工程 新建一个Hello world详细步骤可以参见 Android教程之三:第一个Android应用,HelloWorld 。创建设置如下: Project name:HelloTe.........
    ▪ [意见反应][官方博客]       [意见反馈][官方博客] 写在AndroidManifest.xml 里 像这个样子: </application> <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> <uses-permission android:name="android.permission.ACCES.........

[1]Java压缩技术相干
    来源: 互联网  发布时间: 2014-02-18
Java压缩技术相关

http://snowolf.iteye.com/blog/465433


    
[2] TextView小组件的应用-附带超链接和跑马灯效果
    来源: 互联网  发布时间: 2014-02-18
TextView小组件的使用--附带超链接和跑马灯效果

一:新建HelloTextView 工程

新建一个Hello world详细步骤可以参见

Android教程之三:第一个Android应用,HelloWorld

。创建设置如下:

  • Project name:HelloTextView
  • Build Target :android 2.2
  • Application name:HelloTextView
  • Package name:com.flysnow
  • create Activity:HelloTextView
  • min SDK 8
  • 然后运行该应用就可以看到TextView的效果,是显示一行字:“Hello World, HelloTextView!”,这是因为新建的Hello项目自带的一个TextView。

    二:分析TextView组件

    TextView是Android中常用的组件之一,可以用他来显示文字,就像一个标签一样,或者你可以认为是html中的span。对于TextView我们最关心的应该是怎么设置显示的文本,怎样设置字体的大小,字体的颜色,字体的样式,

    其实很简单,TextView中提供了大量的属性帮我们配置TextView。

    1.修改xml配置文件实现。

    我们修改main.xml如下:

    Xml代码  
  • <?xml version="1.0" encoding="utf-8"?>  
  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  •     android:orientation="vertical"  
  •     android:layout_width="fill_parent"  
  •     android:layout_height="fill_parent"  
  •     >  
  • <TextView     
  •     android:layout_width="fill_parent"    
  •     android:layout_height="wrap_content"  
  •     android:textColor="#ff0000"  
  •     android:textSize="24sp"  
  •     android:text  
  •     android:text="@string/hello"  
  •     />  
  • </LinearLayout>  
  • <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:textColor="#ff0000"
        android:textSize="24sp"
        android:text
        android:text="@string/hello"
        />
    </LinearLayout>

     这里增加了三个属性的设置,分别是android:textColor="#ff0000"设置字体为红色,android:textSize="24sp"设置字体为24sp, android:text设置字体加粗,预览效果如下图:


    看到我们的TextView的内容已经变成红色,24sp大,加粗。。

    2.修改java代码实现。

    同样我们不修改xml文件,而是通过java编码来实现上面的图示效果,首先我们先给这个TextView分配一个id,也就是这个TextView的标记记号,方便我们找到他。在main.xml的TextView中加入android:id="@+id/text_view"就可以为该TextView分配一个id。。这里@+id/是表示在R类的id类下新增常量字段,这里的常量字段是text_view。

    下面修改HelloTextView类如下:

    Java代码  
  • package com.flysnow;   
  •   
  • import android.app.Activity;   
  • import android.graphics.Color;   
  • import android.graphics.Typeface;   
  • import android.os.Bundle;   
  • import android.util.TypedValue;   
  • import android.widget.TextView;   
  •   
  • public class HelloTextView extends Activity {   
  •     /** Called when the activity is first created. */  
  •     @Override  
  •     public void onCreate(Bundle savedInstanceState) {   
  •         super.onCreate(savedInstanceState);   
  •         setContentView(R.layout.main);//设置内容显示的xml布局文件   
  •         TextView textView=(TextView)findViewById(R.id.text_view);//取得我们的TextView组件   
  •         textView.setTextColor(Color.RED);//设置成红色   
  •         textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//设置成24sp   
  •         textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗   
  •     }   
  • }  
  • package com.flysnow;
    
    import android.app.Activity;
    import android.graphics.Color;
    import android.graphics.Typeface;
    import android.os.Bundle;
    import android.util.TypedValue;
    import android.widget.TextView;
    
    public class HelloTextView extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);//设置内容显示的xml布局文件
            TextView textView=(TextView)findViewById(R.id.text_view);//取得我们的TextView组件
            textView.setTextColor(Color.RED);//设置成红色
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//设置成24sp
            textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗
        }
    }

     最终结果和上图一样的,这说明通过代码和xml配置都可以定制TextView,但是推荐使用xml进行定制,使用java代码控制逻辑,这符合mvc模式,也符合Android的设计思想。

    飞雪无情 写道
    这里说一下度量单位。度量单位有很多,如px,pt,dip,sp等等。不过建议应该使用sp作为字体大小的单位,使用dip作为其他元素的单位。。因为sp是刻度无关的像素,更重要的是他可以根据用户的字体大小的首选项进行缩放,这才是重要的,这样当你调整了整体的字体大小时不至于使得个别字体的大小不一致而影响美观。
     三:TextView的一些有用的实例
  • TextView的超链接形势。我们应该都见过html中的超链接,加一个a标记就可以让一段文字变成超链接的形式,可以点击到连接的地址。那么TextView可以实现吗?作为强大的TextView当然不会忘记这一点。TextView为我们提供了android:autoLink属性,只要把他设置成“web”,那么该TextView中的是网址形势的文件就会自动变成超链接的形式。好了,耳听为虚,眼见为实,看下面的例子。修改strings.xml为:
    Xml代码  
  • <?xml version="1.0" encoding="utf-8"?>  
  • <resources>  
  •     <string name="hello">我的博客地址是:http://flysnow.iteye.com    \n我的电话是:400-34534-500\n我的email是12235@163.com</string>  
  •     <string name="app_name">HelloTextView</string>  
  • </resources>  
  • <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="hello">我的博客地址是:http://flysnow.iteye.com    \n我的电话是:400-34534-500\n我的email是12235@163.com</string>
        <string name="app_name">HelloTextView</string>
    </resources>
      修改main.xml为:
    Xml代码  
  • <?xml version="1.0" encoding="utf-8"?>  
  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  •     android:orientation="vertical"  
  •     android:layout_width="fill_parent"  
  •     android:layout_height="fill_parent"  
  •     >  
  • <TextView    
  •     android:id="@+id/text_view"  
  •     android:autoLink="web"  
  •     android:layout_width="fill_parent"    
  •     android:layout_height="wrap_content"  
  •     android:text="@string/hello"  
  •     />  
  • </LinearLayout>  
  • <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView 
    	android:id="@+id/text_view"
    	android:autoLink="web"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="@string/hello"
        />
    </LinearLayout>
     然后把HelloTextView类中的那一段设置文本颜色、大小和样式的代码注释掉,运行程序就会看到如下图的效果:

     当我们点击蓝色的我的博客的网址的时候,Android系统就会调用默认的web浏览器打开我的博客。

     有的朋友已经注意到了,文本里我还写了我的电话和email,难道TextView也支持电话和email超链接吗?没错,的确支持,当我们设置android:autoLink="phone"的时候,文本里的电话就会变成蓝色超链接形式,点击就会打开拨号界面等待你按通话键拨号,email也是同理。。


    当我们把 android:autoLink换成phone的时候发现网址不超连接了,换成email也是一样。难道我们不能一下子让网址,电话,email都超链接吗?答案是肯定的,这时候我们可以把 android:autoLink设置成all,这样里面的网址、电话和email就都可以超链接了。

    2.跑马丁效果。有时候我们要显示的文本较长,TextView不能完全显示,这时候可以通过这中跑马灯的方式让文本移动展示,达到了既不占用地方又能完全看到文本的目的。这里直接复用农民伯伯的跑马灯代码:

    Xml代码  
  • <?xml version="1.0" encoding="utf-8"?>  
  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  •     android:orientation="vertical"  
  •     android:layout_width="fill_parent"  
  •     android:layout_height="fill_parent"  
  •     >  
  • <TextView    
  •     android:id="@+id/text_view"  
  •     android:autoLink="all"  
  •     android:layout_width="fill_parent"    
  •     android:layout_height="wrap_content"  
  •     android:text="@string/hello"  
  •     android:ellipsize="marquee"    
  •     android:focusable="true"    
  •     android:marqueeRepeatLimit="marquee_forever"    
  •     android:focusableInTouchMode="true"    
  •     android:scrollHorizontally="true"/>  
  • </LinearLayout>  
  • <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView 
    	android:id="@+id/text_view"
    	android:autoLink="all"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:ellipsize="marquee" 
        android:focusable="true" 
        android:marqueeRepeatLimit="marquee_forever" 
        android:focusableInTouchMode="true" 
        android:scrollHorizontally="true"/>
    </LinearLayout>

     

    然后为TextView设置一个很长的字符串。运行就可以看到横向移动的效果。

     设置的属性说明可以参考TextView的文档,这里也有中文版本:TextView中文API文档   

    这里要进行说明的是:以上设置在大部分情况下都会成功的展示跑马灯样式,但是在一些复杂的布局中就会看不到任何文字。比如我开发的Android应用“我团”,在展示团购详细信息页面,我自定义了一个标题栏让其显示团购的信息,想让其跑马灯的方式显示,但是使用了上述代码后看不到文字,其实是文字被撑下来的,这时候我们设置android:singleLine="true"以单行的方式展示就好了。所以请以后实现跑马灯效果的时候最好加上android:singleLine="true"单行展示。。

    四:小结

    好了,一个TextView也啰嗦了那么多,希望大家能听明白,最后两个实用的例子能帮助大家更好的学习和使用TextView。。这两天JE挂了,没来得及更新,对不起大家了。最近忙于升级“我团”应用,也只能网上10点后才能上网写。可能更新会很慢,请见谅,谢谢各位的支持

    转自:http://flysnow.iteye.com/blog/822358


        
    [3] [意见反应][官方博客]
        来源: 互联网  发布时间: 2014-02-18
    [意见反馈][官方博客]

    写在AndroidManifest.xml 里

    像这个样子:

        </application>
        	<uses-permission
    		android:name="android.permission.RUN_INSTRUMENTATION" />
    	<uses-permission
    		android:name="android.permission.ACCESS_NETWORK_STATE">
    	</uses-permission>
    	<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    	<uses-permission
    		android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    	</uses-permission>

     

     

    String
    ACCESS_CHECKIN_PROPERTIES
    Allows read/write access to the "prop

    Technorati Tags: Android,permission,Manifest
    erties" table in the checkin database, to change values that get uploaded.

    String
    ACCESS_COARSE_LOCATION
    Allows an application to access coarse (e.g., Cell-ID, WiFi) location

    String
    ACCESS_FINE_LOCATION
    Allows an application to access fine (e.g., GPS) location

    String
    ACCESS_LOCATION_EXTRA_COMMANDS
    Allows an application to access extra location provider commands

    String
    ACCESS_MOCK_LOCATION
    Allows an application to create mock location providers for testing

    String
    ACCESS_NETWORK_STATE
    Allows applications to access information about networks

    String
    ACCESS_SURFACE_FLINGER
    Allows an application to use SurfaceFlinger's low level features

    String
    ACCESS_WIFI_STATE
    Allows applications to access information about Wi-Fi networks

    String
    ACCOUNT_MANAGER
    Allows applications to call into AccountAuthenticators.

    String
    AUTHENTICATE_ACCOUNTS
    Allows an application to act as an AccountAuthenticator for the AccountManager

    String
    BATTERY_STATS
    Allows an application to collect battery statistics

    String
    BIND_APPWIDGET
    Allows an application to tell the AppWidget service which application can access AppWidget's data.

    String
    BIND_INPUT_METHOD
    Must be required by input method services, to ensure that only the system can bind to them.

    String
    BLUETOOTH
    Allows applications to connect to paired bluetooth devices

    String
    BLUETOOTH_ADMIN
    Allows applications to discover and pair bluetooth devices

    String
    BRICK
    Required to be able to disable the device (very dangerous!).

    String
    BROADCAST_PACKAGE_REMOVED
    Allows an application to broadcast a notification that an application package has been removed.

    String
    BROADCAST_SMS
    Allows an application to broadcast an SMS receipt notification

    String
    BROADCAST_STICKY
    Allows an application to broadcast sticky intents.

    String
    BROADCAST_WAP_PUSH
    Allows an application to broadcast a WAP PUSH receipt notification

    String
    CALL_PHONE
    Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.

    String
    CALL_PRIVILEGED
    Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed.

    String
    CAMERA
    Required to be able to access the camera device.

    String
    CHANGE_COMPONENT_ENABLED_STATE
    Allows an application to change whether an application component (other than its own) is enabled or not.

    String
    CHANGE_CONFIGURATION
    Allows an application to modify the current configuration, such as locale.

    String
    CHANGE_NETWORK_STATE
    Allows applications to change network connectivity state

    String
    CHANGE_WIFI_MULTICAST_STATE
    Allows applications to enter Wi-Fi Multicast mode

    String
    CHANGE_WIFI_STATE
    Allows applications to change Wi-Fi connectivity state

    String
    CLEAR_APP_CACHE
    Allows an application to clear the caches of all installed applications on the device.

    String
    CLEAR_APP_USER_DATA
    Allows an application to clear user data

    String
    CONTROL_LOCATION_UPDATES
    Allows enabling/disabling location update notifications from the radio.

    String
    DELETE_CACHE_FILES
    Allows an application to delete cache files.

    String
    DELETE_PACKAGES
    Allows an application to delete packages.

    String
    DEVICE_POWER
    Allows low-level access to power management

    String
    DIAGNOSTIC
    Allows applications to RW to diagnostic resources.

    String
    DISABLE_KEYGUARD
    Allows applications to disable the keyguard

    String
    DUMP
    Allows an application to retrieve state dump information from system services.

    String
    EXPAND_STATUS_BAR
    Allows an application to expand or collapse the status bar.

    String
    FACTORY_TEST
    Run as a manufacturer test application, running as the root user.

    String
    FLASHLIGHT
    Allows access to the flashlight

    String
    FORCE_BACK
    Allows an application to force a BACK operation on whatever is the top activity.

    String
    GET_ACCOUNTS
    Allows access to the list of accounts in the Accounts Service

    String
    GET_PACKAGE_SIZE
    Allows an application to find out the space used by any package.

    String
    GET_TASKS
    Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.

    String
    GLOBAL_SEARCH
    This permission can be used on content providers to allow the global search system to access their data.

    String
    HARDWARE_TEST
    Allows access to hardware peripherals.

    String
    INJECT_EVENTS
    Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.

    String
    INSTALL_LOCATION_PROVIDER
    Allows an application to install a location provider into the Location Manager

    String
    INSTALL_PACKAGES
    Allows an application to install packages.

    String
    INTERNAL_SYSTEM_WINDOW
    Allows an application to open windows that are for use by parts of the system user interface.

    String
    INTERNET
    Allows applications to open network sockets.

    String
    MANAGE_ACCOUNTS
    Allows an application to manage the list of accounts in the AccountManager

    String
    MANAGE_APP_TOKENS
    Allows an application to manage (create, destroy, Z-order) application tokens in the window manager.

    String
    MASTER_CLEAR

    String
    MODIFY_AUDIO_SETTINGS
    Allows an application to modify global audio settings

    String
    MODIFY_PHONE_STATE
    Allows modification of the telephony state - power on, mmi, etc.

    String
    MOUNT_FORMAT_FILESYSTEMS
    Allows formatting file systems for removable storage.

    String
    MOUNT_UNMOUNT_FILESYSTEMS
    Allows mounting and unmounting file systems for removable storage.

    String
    PERSISTENT_ACTIVITY
    Allow an application to make its activities persistent.

    String
    PROCESS_OUTGOING_CALLS
    Allows an application to monitor, modify, or abort outgoing calls.

    String
    READ_CALENDAR
    Allows an application to read the user's calendar data.

    String
    READ_CONTACTS
    Allows an application to read the user's contacts data.

    String
    READ_FRAME_BUFFER
    Allows an application to take screen shots and more generally get access to the frame buffer data

    String
    READ_HISTORY_BOOKMARKS
    Allows an application to read (but not write) the user's browsing history and bookmarks.

    String
    READ_INPUT_STATE
    Allows an application to retrieve the current state of keys and switches.

    String
    READ_LOGS
    Allows an application to read the low-level system log files.

    String
    READ_OWNER_DATA
    Allows an application to read the owner's data.

    String
    READ_PHONE_STATE
    Allows read only access to phone state.

    String
    READ_SMS
    Allows an application to read SMS messages.

    String
    READ_SYNC_SETTINGS
    Allows applications to read the sync settings

    String
    READ_SYNC_STATS
    Allows applications to read the sync stats

    String
    REBOOT
    Required to be able to reboot the device.

    String
    RECEIVE_BOOT_COMPLETED
    Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting.

    String
    RECEIVE_MMS
    Allows an application to monitor incoming MMS messages, to record or perform processing on them.

    String
    RECEIVE_SMS
    Allows an application to monitor incoming SMS messages, to record or perform processing on them.

    String
    RECEIVE_WAP_PUSH
    Allows an application to monitor incoming WAP push messages.

    String
    RECORD_AUDIO
    Allows an application to record audio

    String
    REORDER_TASKS
    Allows an application to change the Z-order of tasks

    String
    RESTART_PACKAGES
    Allows an application to restart other applications.

    String
    SEND_SMS
    Allows an application to send SMS messages.

    String
    SET_ACTIVITY_WATCHER
    Allows an application to watch and control how activities are started globally in the system.

    String
    SET_ALWAYS_FINISH
    Allows an application to control whether activities are immediately finished when put in the background.

    String
    SET_ANIMATION_SCALE
    Modify the global animation scaling factor.

    String
    SET_DEBUG_APP
    Configure an application for debugging.

    String
    SET_ORIENTATION
    Allows low-level access to setting the orientation (actually rotation) of the screen.

    String
    SET_PREFERRED_APPLICATIONS
    This constant is deprecated. No longer useful, see addPackageToPreferred(String) for details.

    String
    SET_PROCESS_LIMIT
    Allows an application to set the maximum number of (not needed) application processes that can be running.

    String
    SET_TIME_ZONE
    Allows applications to set the system time zone

    String
    SET_WALLPAPER
    Allows applications to set the wallpaper

    String
    SET_WALLPAPER_HINTS
    Allows applications to set the wallpaper hints

    String
    SIGNAL_PERSISTENT_PROCESSES
    Allow an application to request that a signal be sent to all persistent processes

    String
    STATUS_BAR
    Allows an application to open, close, or disable the status bar and its icons.

    String
    SUBSCRIBED_FEEDS_READ
    Allows an application to allow access the subscribed feeds ContentProvider.

    String
    SUBSCRIBED_FEEDS_WRITE

    String
    SYSTEM_ALERT_WINDOW
    Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications.

    String
    UPDATE_DEVICE_STATS
    Allows an application to update device statistics.

    String
    USE_CREDENTIALS
    Allows an application to request authtokens from the AccountManager

    String
    VIBRATE
    Allows access to the vibrator

    String
    WAKE_LOCK
    Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming

    String
    WRITE_APN_SETTINGS
    Allows applications to write the apn settings

    String
    WRITE_CALENDAR
    Allows an application to write (but not read) the user's calendar data.

    String
    WRITE_CONTACTS
    Allows an application to write (but not read) the user's contacts data.

    String
    WRITE_EXTERNAL_STORAGE
    Allows an application to write to external storage

    String
    WRITE_GSERVICES
    Allows an application to modify the Google service map.

    String
    WRITE_HISTORY_BOOKMARKS
    Allows an application to write (but not read) the user's browsing history and bookmarks.

    String
    WRITE_OWNER_DATA
    Allows an application to write (but not read) the owner's data.

    String
    WRITE_SECURE_SETTINGS
    Allows an application to read or write the secure system settings.

    String
    WRITE_SETTINGS
    Allows an application to read or write the system settings.

    String
    WRITE_SMS
    Allows an application to write SMS messages.

    String
    WRITE_SYNC_SETTINGS
    Allows applications to write the sync settings

     


        
    最新技术文章:
    ▪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,