很久没有更新自己的博客,也许是因为忙,但真的不知道究竟忙了写什么,以后还是有时间就抽点时间来写博客,一方面是长时间不组织语言,有很多想法,说话写字都挤不出半句话来,二来,我需要学会总结,很多经验可能当时很有感触,过一阵就会忘记。不管写的怎么样,坚持写点什么总是好的。看到祥健转载的人民日报一篇文章,有点收获 ,分享一下。
Continue reading “随便写点什么。”android 屏幕图标尺寸规范
1. 程序启动图标:
ldpi (120 dpi)
小屏
mdpi (160 dpi)
中屏
hdpi (240 dpi)
大屏
xhdpi (320 dpi)
特大屏
36 x 36 px
48 x 48 px
72 x 72 px
96 x 96 px
ICON圆角半径
iTunes Artwork icon ───────────────────────── 512px (90px)
App icon(iPhone4) ────────────────────────── 114px (20px)
App icon(iPad) ───────────────────────────── 72px (12px)
App icon(iPhone 3G/3GS) ───────────────────── 57px(10px)
Spotlight/Settings icon icon(iPhone4) ───────────── 58px (10px)
Spotlight/Settings icon icon(iPhone 3G/3GS/iPad) ──── 29px (9px)
android中的dialog
在Android开发中,我们经常需要在界面上弹出一些对话框,比如询问用户或者让用户选择。 下面总结了下dialog的一些样式。
1.该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式。
创建dialog对话框方法代码如下:
- protected void dialog() {
- AlertDialog.Builder builder = new Builder(Main.this);
- builder.setMessage(“确认退出吗?”);
- builder.setTitle(“提示”);
- builder.setPositiveButton(“确认”, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- Main.this.finish();
- }
- });
- builder.setNegativeButton(“取消”, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- builder.create().show();
- }
在onKeyDown(int keyCode, KeyEvent event)方法中调用此方法
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
- dialog();
- }
- return false;
- }
2.改变了对话框的图表,添加了三个按钮
创建dialog的方法代码如下:
- Dialog dialog = new AlertDialog.Builder(this).setIcon(
- android.R.drawable.btn_star).setTitle(“喜好调查”).setMessage(
- “你喜欢李连杰的电影吗?”).setPositiveButton(“很喜欢”,
- new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Toast.makeText(Main.this, “我很喜欢他的电影。”,
- Toast.LENGTH_LONG).show();
- }
- }).setNegativeButton(“不喜欢”, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Toast.makeText(Main.this, “我不喜欢他的电影。”, Toast.LENGTH_LONG)
- .show();
- }
- }).setNeutralButton(“一般”, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- Toast.makeText(Main.this, “谈不上喜欢不喜欢。”, Toast.LENGTH_LONG)
- .show();
- }
- }).create();
- dialog.show();
3.信息内容是一个简单的View类型
创建dialog方法的代码如下:
- new AlertDialog.Builder(this).setTitle(“请输入”).setIcon(
- android.R.drawable.ic_dialog_info).setView(
- new EditText(this)).setPositiveButton(“确定”, null)
- .setNegativeButton(“取消”, null).show();
4.信息内容是一组单选框
创建dialog方法的代码如下:
- new AlertDialog.Builder(this).setTitle(“单选框”).setIcon(
- android.R.drawable.ic_dialog_info).setSingleChoiceItems(
- new String[] { “Item1”, “Item2” }, 0,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- }).setNegativeButton(“取消”, null).show();
5.信息内容是一组多选框
创建dialog方法的代码如下:
- new AlertDialog.Builder(this).setTitle(“复选框”).setMultiChoiceItems(
- new String[] { “Item1”, “Item2” }, null, null)
- .setPositiveButton(“确定”, null)
- .setNegativeButton(“取消”, null).show();
6.信息内容是一组简单列表项
创建dialog的方法代码如下:
- new AlertDialog.Builder(this).setTitle(“列表框”).setItems(
- new String[] { “Item1”, “Item2” }, null).setNegativeButton(
- “确定”, null).show();
7.信息内容是一个自定义的布局
dialog布局文件代码如下:
- <?xml version=”1.0″ encoding=”utf-8″?>
- <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
- android:layout_height=”wrap_content” android:layout_width=”wrap_content”
- android:background=”#ffffffff” android:orientation=”horizontal”
- android:id=”@+id/dialog”>
- <TextView android:layout_height=”wrap_content”
- android:layout_width=”wrap_content”
- android:id=”@+id/tvname” android:text=”姓名:” />
- <EditText android:layout_height=”wrap_content”
- android:layout_width=”wrap_content” android:id=”@+id/etname” android:minWidth=”100dip”/>
- </LinearLayout>
创建dialog方法的代码如下:
- LayoutInflater inflater = getLayoutInflater();
- View layout = inflater.inflate(R.layout.dialog,
- (ViewGroup) findViewById(R.id.dialog));
- new AlertDialog.Builder(this).setTitle(“自定义布局”).setView(layout)
- .setPositiveButton(“确定”, null)
- .setNegativeButton(“取消”, null).show();
好了,以上7种Android dialog对话框的使用方法就介绍到这里了,基本都全了,如果大家在android开发过程中遇到dialog的时候就可以拿出来看看。
android 调用系统设置界面
在编写android应用程序时,如果需要调用系统原生的管理应用程序界面呢?本人在一个项目中遇到过,本人没有发现这方面现成的intent,不过通过看源代码实现了。
android源代码application_settings.xml
-
<PreferenceScreen
-
android:title="@string/manageapplications_settings_title"
-
android:summary="@string/manageapplications_settings_summary">
-
<intent android:action="android.intent.action.MAIN"
-
android:targetPackage="com.android.settings"
-
android:targetClass="com.android.settings.ManageApplications" />
-
</PreferenceScreen>
熟悉PreferenceScreen的朋友应该知道如何做了,如果不熟悉的朋友,文章最后贴出一篇文章,大家参考一下就知道了,根据xml的描述,我们可以用如下代码调用系统原生的管理应用程序界面
-
Intent intent = new Intent();
-
intent.setAction("android.intent.action.MAIN");
-
intent.setClassName("com.android.settings", "com.android.settings.ManageApplications");
-
startActivity(intent);
如果要进入某个软件详细设置界面 可以如下操作:
“Android系统设置->应用程序->管理应用程序”列表下,列出了系统已安装的应用程序。选择其中一个程序,则进入“应用程序信息(Application Info)”界面。这个界面显示了程序名称、版本、存储、权限等信息,并有卸载、停止、清除缓存等按钮,可谓功能不少。如果在编写相关程序时(比如任务管理器)可以调用这个面板,自然提供了很大的方便。那么如何实现呢?
在最新的Android SDK 2.3(API Level 9)中,提供了这样的接口。在文档路径
docs/reference/android/provider/Settings.html#ACTION_APPLICATION_DETAILS_SETTINGS
下,有这样的描述:
public static final String ACTION_APPLICATION_DETAILS_SETTINGS Since: API Level 9
Activity Action: Show screen of details about a particular application.
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
Input: The Intent's data URI specifies the application package name to be shown, with the "package" scheme. That is "package:com.my.app".
Output: Nothing.
Constant Value: "android.settings.APPLICATION_DETAILS_SETTINGS"
就是说,我们只要以android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS作为Action;“package:应用程序的包名”作为URI,就可以用startActivity启动应用程序信息界面了。代码如下:
-
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
-
Uri uri = Uri.fromParts(SCHEME, packageName, null);
-
intent.setData(uri);
-
startActivity(intent);
-
// utility method used to start sub activity
-
private void startApplicationDetailsActivity() {
-
// Create intent to start new activity
-
Intent intent = new Intent(Intent.ACTION_VIEW);
-
intent.setClass(this, InstalledAppDetails.class);
-
intent.putExtra(APP_PKG_NAME, mCurrentPkgName);
-
// start new activity to display extended information
-
startActivityForResult(intent, INSTALLED_APP_DETAILS);
-
}
-
Intent i = new Intent(Intent.ACTION_VIEW);
-
i.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");
-
i.putExtra("com.android.settings.ApplicationPkgName", packageName);
-
startActivity(i);
-
private static final String SCHEME = "package";
-
/**
-
* 调用系统InstalledAppDetails界面所需的Extra名称(用于Android 2.1及之前版本)
-
*/
-
private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
-
/**
-
* 调用系统InstalledAppDetails界面所需的Extra名称(用于Android 2.2)
-
*/
-
private static final String APP_PKG_NAME_22 = "pkg";
-
/**
-
* InstalledAppDetails所在包名
-
*/
-
private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
-
/**
-
* InstalledAppDetails类名
-
*/
-
private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
-
/**
-
* 调用系统InstalledAppDetails界面显示已安装应用程序的详细信息。 对于Android 2.3(Api Level
-
* 9)以上,使用SDK提供的接口; 2.3以下,使用非公开的接口(查看InstalledAppDetails源码)。
-
*
-
* @param context
-
*
-
* @param packageName
-
* 应用程序的包名
-
*/
-
public static void showInstalledAppDetails(Context context, String packageName) {
-
Intent intent = new Intent();
-
final int apiLevel = Build.VERSION.SDK_INT;
-
if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口
-
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
-
Uri uri = Uri.fromParts(SCHEME, packageName, null);
-
intent.setData(uri);
-
} else { // 2.3以下,使用非公开的接口(查看InstalledAppDetails源码)
-
// 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。
-
final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
-
: APP_PKG_NAME_21);
-
intent.setAction(Intent.ACTION_VIEW);
-
intent.setClassName(APP_DETAILS_PACKAGE_NAME,
-
APP_DETAILS_CLASS_NAME);
-
intent.putExtra(appPkgName, packageName);
-
}
-
context.startActivity(intent);
-
}
android中 TextView设置滚动条
TextView实现滚动的三种方式:
1、嵌套在ScrollView或者HorizontalScrollView中
<scrollview android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="vertical">
<textview android:text="http://orgcent.com …"/>
</scrollview>
水平滚动:使用标签<horizontalscrollview></horizontalscrollview>
一定要注意的是 ScrollView要放到 textView外边 才能生效地 。
2、设置ScrollingMovementMethod
代码中添加:
XML中配置:
特别要注意 2条件同时满足才能效。
3、使用Scroller来自定义TextView
点击查看:android自定义View-垂直滚动的TextView
如果需要删除TextView的 滚动条 可以 设置ScrollView 的xml的属性 android:scrollbars="none"