導航:首頁 > 操作系統 > androidmenu布局

androidmenu布局

發布時間:2025-02-24 15:15:40

1. 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特性和使用匯總(一)》

2. 在android工程中,res目錄下又有anim、drawable、layout、menu、raw、values和xml文件夾,分別用來保存

res目錄主要是存放資源文件的!
layout 布局 這個就是你經常看到的與用戶交互的界面的 xml 文件,就是各個 view 的排列和嵌套,沒什 么好說的啦 風格和主題、 風格主要是指 view 的顯示風格 ;
anim 一般是設置動畫,畫資源分為兩種,一是實現圖片的 translate、scale、rotate、alpha 四種變化。還可以設置 動畫的播放特性;另一種是幀動畫,逐幀播放設置的資源;
drawable 主要是是存放所使用的圖片的!
menu:菜單 菜單即可以從代碼中實現也可以在資源文件中配置;
把圖像文件放在 res/raw/ 目錄下,這樣可以避免被自動優化。
values 是用程序人員設置的一些常量的XML文件,便於修改和使用,一般有Strings,colors等

assets 文件夾是存放不進行編譯加工的原生文件,即該文件夾裡面的文件不會像 xml, java 文件被預編譯,可以存放一些圖片,html,js, css 等文件。

閱讀全文

與androidmenu布局相關的資料

熱點內容
怎麼區分物理伺服器 瀏覽:740
安卓開發板能幹什麼 瀏覽:361
程序員學五筆 瀏覽:316
linux編程下載文件 瀏覽:6
java基礎面試編程題 瀏覽:464
linux數學計算 瀏覽:775
android手機電腦同步 瀏覽:289
簡明python教程書在線觀看 瀏覽:744
理想論壇多空出擊指標源碼 瀏覽:685
擴散更新演算法 瀏覽:557
當代大學德語pdf 瀏覽:506
打程序員代碼被暴打 瀏覽:390
怎麼看手機支持mrp和app 瀏覽:466
python爬取百度貼吧信息 瀏覽:635
手機怎麼連好輕app 瀏覽:399
真實賽車3安卓如何登錄 瀏覽:733
解壓壓縮包要誰的密碼 瀏覽:746
微信看漲跌源碼 瀏覽:70
android全局service 瀏覽:291
飛豬app關注怎麼取消 瀏覽:437