先来看一个android屏幕全屏实现代码
代码如下 | 复制代码 |
@Override newsNameList = (ListView) findViewById(R.id.newsnamelist); showPage = (TextView) findViewById(R.id.newslistshowpage); |
现在我们还可以来判断是全屏或非全屏
代码如下 | 复制代码 |
public void onCreate(Bundle savedInstanceState) { } |
1.对包名的判断,异常则说明不存在:
代码如下 | 复制代码 |
|
2.对类名的判断,异常则说明不存在:
代码如下 | 复制代码 |
|
注:根据Android的安全机制,在使用TelephonyManager时,必须在AndroidManifest.xml中添加
name="READ_PHONE_STATE" /> 否则无法获得系统的许可。
Android开发平台中,可通过TelephonyManager 获取本机号码。
例
代码如下 | 复制代码 |
private String getPhoneNumber(){ |
或这样写
代码如下 | 复制代码 |
TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); txtPhoneNumber.setText(phoneMgr.getLine1Number()); //txtPhoneNumber |
是一个EditText 用于显示手机号
本文章来给大家介绍两段Android实现图片循环播放程序代码,有需要了解的朋友可进入参考。SDK后个不错的实例
代码如下 | 复制代码 |
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); //接着我们要实现Runnable方法,也就是准时变动现在播放图片的ID public class runner implements Runnable { // TODO Auto-generated method stub |
Gallery 中的图片循环播放图片的实现
主要讲的就是一个循环播放图片的实现,我们这里主要还是用到了arraylisy,利用arraylist来控制里面的图片位置,这样就相对简单和容易控制循环了,我们只要牵扯到自定义的arrayadapter还是要注意继承getview在里面设置一个变量参数,就可以来实现变化,这才是最关键的。我们来看看代码吧:
代码如下 | 复制代码 |
public class Splash extends Activity { ArrayList objects = new ArrayList(); Gallery g; int i = 0; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.photos); g = (Gallery) findViewById(R.id.gallery); objects.add(getResources().getDrawable(R.drawable.icon)); objects.add(getResources().getDrawable(R.drawable.icon)); objects.add(getResources().getDrawable(R.drawable.icon)); objects.add(getResources().getDrawable(R.drawable.icon)); objects.add(getResources().getDrawable(R.drawable.icon)); objects.add(getResources().getDrawable(R.drawable.icon)); g.setAdapter(new CustomAdapter(this, objects)); g.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { Log.i(“”, “selected ” + arg2); } @Override public void onNothingSelected(AdapterView arg0) {} }); } @Override public void onBackPressed() { g.setSelection(i++); } private class CustomAdapter extends BaseAdapter { private Context mCtx; private List objects; public int getCount() { return this.objects.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public CustomAdapter(Context context, ArrayList objects) { super(); mCtx = context; this.objects = objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView row = (ImageView) convertView; if (row == null) { row = new ImageView(mCtx); row.setBackgroundDrawable(objects.get(position)); } return row; } } } |
viewpager 循环播放图片 本站有很多种例子了,这里就不介绍了
本文章来给大家详细介绍Android开发时间日期格式国际化实现方法,有需要了解日期格式化的朋友可进入参考参考。DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar.
To format a date for the current Locale, use one of the static factory methods:
代码如下 | 复制代码 |
myString = DateFormat.getDateInstance().format(myDate); |
If you are formatting multiple dates, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.
代码如下 | 复制代码 |
DateFormat df = DateFormat.getDateInstance(); |
To format a number for a different locale, specify it in the call to getDateInstance:
代码如下 | 复制代码 |
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE); |
DateFormat can also be used to parse strings:
代码如下 | 复制代码 |
myDate = df.parse(myString); |
例子
代码如下 | 复制代码 |
public static CharSequence formatTimeInListForOverSeaUser( |