當前位置:首頁 » 安卓系統 » android導航demo

android導航demo

發布時間: 2024-02-09 10:00:23

⑴ android 怎麼實現左側導航欄

Android左側推出導航菜單可以讓Activity繼承PopupWindow類來實現的彈出窗體,布局可以根據自己定義設計。彈出效果主要使用了translate和alpha樣式實現。具體的做法是下列代碼:
第一步:設計彈出窗口xml:

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="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
>

<LinearLayout
android:id="@+id/pop_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="@drawable/btn_style_alert_dialog_background"
>

<Button
android:id="@+id/btn_take_photo"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="拍照"
android:background="@drawable/btn_style_alert_dialog_button"
android:textStyle="bold"
/>

<Button
android:id="@+id/btn_pick_photo"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="從相冊選擇"
android:background="@drawable/btn_style_alert_dialog_button"
android:textStyle="bold"
/>

<Button
android:id="@+id/btn_cancel"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="取消"
android:background="@drawable/btn_style_alert_dialog_cancel"
android:textColor="#ffffff"
android:textStyle="bold"

/>
</LinearLayout>
</RelativeLayout>
第二步:創建SelectPicPopupWindow類繼承PopupWindow:

java代碼
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class SelectPicPopupWindow extends PopupWindow {

private Button btn_take_photo, btn_pick_photo, btn_cancel;
private View mMenuView;

public SelectPicPopupWindow(Activity context,OnClickListener itemsOnClick) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mMenuView = inflater.inflate(R.layout.alert_dialog, null);
btn_take_photo = (Button) mMenuView.findViewById(R.id.btn_take_photo);
btn_pick_photo = (Button) mMenuView.findViewById(R.id.btn_pick_photo);
btn_cancel = (Button) mMenuView.findViewById(R.id.btn_cancel);
//取消按鈕
btn_cancel.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
//銷毀彈出框
dismiss();
}
});
//設置按鈕監聽
btn_pick_photo.setOnClickListener(itemsOnClick);
btn_take_photo.setOnClickListener(itemsOnClick);
//設置SelectPicPopupWindow的View
this.setContentView(mMenuView);
//設置SelectPicPopupWindow彈出窗體的寬
this.setWidth(LayoutParams.FILL_PARENT);
//設置SelectPicPopupWindow彈出窗體的高
this.setHeight(LayoutParams.WRAP_CONTENT);
//設置SelectPicPopupWindow彈出窗體可點擊
this.setFocusable(true);
//設置SelectPicPopupWindow彈出窗體動畫效果
this.setAnimationStyle(R.style.AnimBottom);
//實例化一個ColorDrawable顏色為半透明
ColorDrawable dw = new ColorDrawable(0xb0000000);
//設置SelectPicPopupWindow彈出窗體的背景
this.setBackgroundDrawable(dw);
//mMenuView添加OnTouchListener監聽判斷獲取觸屏位置如果在選擇框外面則銷毀彈出框
mMenuView.setOnTouchListener(new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {

int height = mMenuView.findViewById(R.id.pop_layout).getTop();
int y=(int) event.getY();
if(event.getAction()==MotionEvent.ACTION_UP){
if(y<height){
dismiss();
}
}
return true;
}
});

}

}

第三步:編寫MainActivity類實現測試:

Java代碼
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MainActivity extends Activity {

//自定義的彈出框類
SelectPicPopupWindow menuWindow;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) this.findViewById(R.id.text);
//把文字控制項添加監聽,點擊彈出自定義窗口
tv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//實例化SelectPicPopupWindow
menuWindow = new SelectPicPopupWindow(MainActivity.this, itemsOnClick);
//顯示窗口
menuWindow.showAtLocation(MainActivity.this.findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); //設置layout在PopupWindow中顯示的位置
}
});
}

//為彈出窗口實現監聽類
private OnClickListener itemsOnClick = new OnClickListener(){

public void onClick(View v) {
menuWindow.dismiss();
switch (v.getId()) {
case R.id.btn_take_photo:
break;
case R.id.btn_pick_photo:
break;
default:
break;
}

}

};

}
上述的代碼實現了從底部彈出,也可以根據PopupWindow類設置從左下部彈出。
Android的對話框有兩種:PopupWindow和AlertDialog。它們的不同點在於:
AlertDialog的位置固定,而PopupWindow的位置可以隨意
AlertDialog是非阻塞線程的,而PopupWindow是阻塞線程的
PopupWindow的位置按照有無偏移分,可以分為偏移和無偏移兩種;按照參照物的不同,可以分為相對於某個控制項(Anchor錨)和相對於父控制項。具體如下
showAsDropDown(View anchor):相對某個控制項的位置(正左下方),無偏移
showAsDropDown(View anchor, int xoff, int yoff):相對某個控制項的位置,有偏移
showAtLocation(View parent, int gravity, int x, int y):相對於父控制項的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以設置偏移或無偏移

⑵ android 微信導航欄的滑動效果(滑塊隨著頁面滑動也跟著平滑)怎麼做,大神有demo嗎

簡單的Actionbar 搭配ViewPager。你在eclipse中new 一個Activity,選擇blank activity,然後在Navigation type選擇ActionBar tabs with ViewPager,就會幫你生成一個demo了。

⑶ 求教android studio大神:用fragment寫一個導航欄,在每個fragment裡面加listview,能實現點擊事件

AndroidStudio製作底部導航欄以及用Fragment實現切換功能,用戶點擊底部導航欄可以實現三個模塊的跳轉。
圖片資源
需要底部導航欄三個點擊按鈕的圖片資源
main_button_1.png,main_button_2.png,main_button_3.png
以及點擊變換的圖片資源
main_button_1_selected.png,
main_button_2_selected.png,
main_button_3_selected.png.
以上圖片資源都放進drawable文件夾
activity_main 布局
在 MainActivity 頁面中主要有兩個區域:
一個是放 Fragment 的 main_body
一個是放底部導航欄的 main_bottom_bar
主要的Fragment代碼塊:

⑷ Android導航欄隱藏與浮現(二)

在 Android導航欄隱藏與浮現(一) 中已經以 Nexus5 為例, Android M 為基礎介紹了怎麼實現底部導航欄的隱藏與浮現,本文將介紹怎麼在設置(輔助功能)中加入控制該功能的開關。

上圖可以看到,應用中加入了一個 Enhance Navigation bar 的選項,該功能開啟後可以長點擊任務鍵(Recent)時,導航欄隱藏;從下不向上滑時,導航欄展示。 關閉後即取消了該功能。下面看一下整體的操作步驟:

在 Settings.apk 中修改相應的資源文件即可,修改中可以參考系統設置中的 Large text , 步驟如下:

修改 ./packages/apps/Settings/res/values-zh-rCN/strings.xml ,添加資源名稱:

修改 ./packages/apps/Settings/res/values/strings.xml ,添加資源名稱:

修改 ./packages/apps/Settings/res/xml/accessibility_settings.xml ,添加開關:

修改 ./frameworks/base/core/java/android/provider/Settings.java ,在內部類 Secure 中添加欄位:

修改文件 ./frameworks/base/packages/SettingsProvider/res/values/defaults.xml ,添加默認開關:

修改文件 ./packages/apps/Settings/src/com/android/settings/accessibility/AccessibilitySettings.java , 修改部分基本和 Large text 的相同,diff後的試圖如下,也可以根據下面提供修改前和修改後的文件,可以使用 diff 工具對比查看。

diff後的文件對比試圖

AccessibilitySettings修改前 AccessibilitySettings修改後

修改 ./frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java ,添加變數:

在recent鍵長點擊處添加開關控制:

使用 mmm 命令針對涉及的模塊進行打包。

使用 make snod 命令生成 system.img 。

兩次的結合完整的解決了導航欄的隱藏與浮現以及功能控制。

刷機需謹慎!刷機需謹慎!刷機需謹慎!如若刷機請提前備份數據!

熱點內容
安卓平板有什麼可以畫對稱的 發布:2024-07-27 09:36:03 瀏覽:132
羊創意腳本 發布:2024-07-27 09:29:30 瀏覽:894
榮耀v20升級存儲 發布:2024-07-27 09:20:19 瀏覽:485
安卓用什麼和電腦傳圖片 發布:2024-07-27 09:02:07 瀏覽:288
存儲過程就是 發布:2024-07-27 08:56:51 瀏覽:131
c語言高級試題 發布:2024-07-27 08:48:30 瀏覽:282
ip伺服器世界上有幾台 發布:2024-07-27 08:46:18 瀏覽:394
金立手機怎麼清理緩存 發布:2024-07-27 08:38:50 瀏覽:311
iphone文件夾不顯示 發布:2024-07-27 08:18:05 瀏覽:774
y510p固態硬碟做緩存 發布:2024-07-27 07:59:34 瀏覽:128