导航:首页 > 操作系统 > androidmenuicon

androidmenuicon

发布时间:2022-12-11 03:58:12

A. android中menu菜单中的图片是怎么加进去的

给这个图片按钮添加一个事件, button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent();
intent.setClass(当前Activity.this, 下一个Activity.class);
startActivity(intent);
当前Activity.finish();//关闭当前Activity
}
});
与普通按钮没有什么区别,一个就是有图片的,一个没有嘛,对它做事件都 一样,只不过显示效果不一样。

B. android中怎么让menu菜单显示在屏幕左上角

用惯了Android的人在刚拿到iPhone的时候,总是会习惯性的用手指从状态栏往下拖一下,这都是给Notification闹的。
不过Notification也确实是1个不错的提示工具,不干扰正常的操作,事后还可以再翻看详细的内容,点击后还可以进入相关的画面查看更具体的内容。
今天我就以代码为主的形式来介绍Notification的使用,包括基本用法,自定义的View,以及更多的控制方法。
另一种Android中常用到的提示方法Toast的用法请参见《教程:在Android中使用Toast进行提示》
我们先看下Notification的几个主要组成部分:
Icon:不解释
Ticker Text:Notification刚出来的时候,在状态栏上滚动的字幕,如果很长,会自动分割滚动

Content Title:Notification展开后的标题
Content Text:Notification展开后的内容

Notification的一般用法
取得NotificationManager
private NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
创建Notification并且显示
//Notification的滚动提示
String tickerText = "My notification, It's a long text! Hello World desiyo?";
//Notification的图标,一般不要用彩色的
int icon = R.drawable.icon_02241_3;

//contentTitle和contentText都是标准的Notification View的内容
//Notification的内容标题,拖下来后看到的标题
String contentTitle="My notification";
//Notification的内容
String contentText="Hello World!";

//Notification的Intent,即点击后转向的Activity
Intent notificationIntent = new Intent(this, this.getClass());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

//创建Notifcation
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
//设定Notification出现时的声音,一般不建议自定义
notification.defaults |= Notification.DEFAULT_SOUND;
//设定如何振动
notification.defaults |= Notification.DEFAULT_VIBRATE;
//指定Flag,Notification.FLAG_AUTO_CANCEL意指点击这个Notification后,立刻取消自身
//这符合一般的Notification的运作规范
notification.flags|=Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
//显示这个notification
mNotificationManager.notify(HELLO_ID, notification);
这是最基本的应用,可以说除了找个合适的图标以外,其它都很简单。

使用自定义View的Notification
同Toast一样,我们也可以自已指定1个View来作为Notification展开后的显示内容,比如说在Android Market中下载的时候,Notification中会显示当前下载的进度,那么我们也来模拟1个这样的效果吧。
首先给出View的定义文件:notification_view_sample.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp"
>
<ImageView android:id="@+id/notificationImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@android:drawable/stat_sys_download"
/>
<TextView android:id="@+id/notificationTitle"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/notificationImage"
android:layout_alignParentRight="true"
android:paddingLeft="6dp"
android:textColor="#FF000000"
/>
<TextView android:id="@+id/notificationPercent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/notificationImage"
android:paddingTop="2dp"
android:textColor="#FF000000"
/>
<ProgressBar android:id="@+id/notificationProgress"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/notificationTitle"
android:layout_alignLeft="@id/notificationTitle"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/notificationPercent"
android:paddingLeft="6dp"
android:paddingRight="3dp"
android:paddingTop="2dp"
style="?android:attr/progressBarStyleHorizontal"
/>
</RelativeLayout>
RelativeLayout的使用,可以参考:《教程:Android各种Layout特性和使用汇总(一)》

C. 我刚学Android不久,用系统自带的Menu,加了图片后怎么没显示出来

4.2上的optionsMenu是放到actionbar上面了,必须要在xml文件中设置showAsAction="always"活着showAsAction="ifRoom"才能在actionbar上显示。只有在actionBar上显示的菜单,才会有图标。要在代码中设置的话,menu.findItem(id).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)。图上面的菜单显示应该是老掉牙的系统了,没有遵循android design guidelines。

D. Android的界面是如何适配多样化屏幕

在研究Android的icon设计之前,有必要先了解Android的界面是如何适配多样化屏幕的。

适配性

上一篇博文中提到,由于同一个UI元素(如100 x100像素的图片)在高精度的屏幕上要比低精度的屏幕上看起来要小,为了让这两个屏幕上的图片看起来效果差不多,可以采用以下两种方法:

E. android如何调用系统的隐藏方法

比如如果要在安卓4.0以上显示菜单的图标

java">publicvoidenableMenuIcon(android.widget.Menumenu){
if(android.os.Build.VERSION.SDK_INT<14)return;//系统在4.0以下时禁用
try{
Classclz=Class.forName("com.android.internal.view.menu.MenuBuilder");//找到要调用的方法所在类
java.lang.reflect.Methodm=clz.getDeclaredMethod("setOptionalIconsVisible",boolean.class);//找到指定参数类型和参数数量的方法名
m.setAccessible(true);//设置可访问该域
m.invoke(menu,true);//模拟这个动态的对象进行调用该方法,并附加方法参数
}catch(Throwablee){}
}
阅读全文

与androidmenuicon相关的资料

热点内容
dvd光盘存储汉子算法 浏览:757
苹果邮件无法连接服务器地址 浏览:962
phpffmpeg转码 浏览:671
长沙好玩的解压项目 浏览:142
专属学情分析报告是什么app 浏览:564
php工程部署 浏览:833
android全屏透明 浏览:732
阿里云服务器已开通怎么办 浏览:803
光遇为什么登录时服务器已满 浏览:301
PDF分析 浏览:484
h3c光纤全工半全工设置命令 浏览:141
公司法pdf下载 浏览:381
linuxmarkdown 浏览:350
华为手机怎么多选文件夹 浏览:683
如何取消命令方块指令 浏览:349
风翼app为什么进不去了 浏览:778
im4java压缩图片 浏览:362
数据查询网站源码 浏览:150
伊克塞尔文档怎么进行加密 浏览:890
app转账是什么 浏览:163