導航:首頁 > 操作系統 > 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光碟存儲漢子演算法 瀏覽:755
蘋果郵件無法連接伺服器地址 瀏覽:960
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:142
專屬學情分析報告是什麼app 瀏覽:563
php工程部署 瀏覽:831
android全屏透明 瀏覽:732
阿里雲伺服器已開通怎麼辦 瀏覽:802
光遇為什麼登錄時伺服器已滿 瀏覽:301
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:141
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:890
app轉賬是什麼 瀏覽:163