① android底部導航欄怎麼做,
可以使用radiogroup做底部導航
radiogroup的屬性自定義,並設置android:button="@null"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:background="@drawable/bottom_bg"
android:orientation="horizontal" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
style="@style/navigation_bottom_radio"
android:drawableTop="@drawable/bottom_home_d"
android:text="@string/home_tv" />
<RadioButton
style="@style/navigation_bottom_radio"
android:drawableTop="@drawable/bottom_looks_d"
android:text="@string/style_tv" />
<RadioButton
style="@style/navigation_bottom_radio"
android:drawableTop="@drawable/bottom_cam"
android:gravity="center"
android:text="拍照"
/>
<RadioButton
style="@style/navigation_bottom_radio"
android:drawableTop="@drawable/bottom_shopping_d"
android:text="@string/shopping_tv" />
<RadioButton
style="@style/navigation_bottom_radio"
android:drawableTop="@drawable/bottom_show_d"
android:text="@string/show_tv" />
</RadioGroup>
</LinearLayout>
<resources>
<style name="navigation_bottom_radio">
<!-- 內部組件的排列 -->
<item name="android:gravity">center_horizontal</item>
<!-- 背景樣式 -->
<item name="android:background">@drawable/style_navigation_radio</item>
<!-- 寬度 -->
<item name="android:layout_width">fill_parent</item>
<!-- 高度 -->
<item name="android:layout_height">wrap_content</item>
<!-- 設置RadioButton的原來圖片為空 -->
<item name="android:button">@null</item>
<!-- 與其他組件寬度占相同比重 -->
<item name="android:layout_weight">1.0</item>
<!-- 底部的空隙 -->
<item name="android:paddingBottom">2.0dip</item>
<!-- 頂部的空隙 -->
<item name="android:paddingTop">2.0dip</item>
<!-- 文字的大小 -->
<item name="android:textSize">11dip</item>
<!-- 文字的顏色 -->
<item name="android:textColor">@color/white</item>
</style>
</resources>
參考:http://blog.csdn.net/longyi_java/article/details/8485826
② 如何實現Android透明導航欄
1.步驟:
1) 創建一個工程,主布局就先做一個ImageView,自己找個好看的圖片做src。
2) 在Activity重寫的onCreate方法中獲得窗口視圖對象(DecorView)
3) 設置DecorView的SystemUiVisibility
4) 設置導航條、狀態欄的顏色–>透明
5) 獲取當前Activity的ActionBar並隱藏
2.具體代碼和注釋:
獲取DecorView對象
@Override
protectedvoidonCreate(BundlesavedInstanceState){
...
ViewdecorView=getWindow().getDecorView();
...
}
設置SystemUiVisibility
intoption=View.SYSTEM_UI_FLAG_FULLSCREEN//全屏標記
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN//布局全屏標記,避免退出全屏模式時內容被覆蓋
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隱藏導航欄標記
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//布局隱藏導航欄標記,同理
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY//粘性沉浸體驗
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE;//確保上述標記穩定//此方法用來設置系統UI的可見性,系統UI包括狀態欄、ActionBar、導航欄devorView.setSystemUiVisibility(option);
設置狀態欄、導航欄的顏色:
getWindow().setStatusBarColor(Color.TRANSPARENT);//Color.TRANSPARENT=0表示#00000000即透明顏色
getWindow().setNavigationBarColor(Color.TRANSPARENT);
獲取本頁面的ActionBar並隱藏起來
ActionBaractionBar=getSupportActionBar();//注意:此處用的Activity繼承的是
AppCompatActivity(它繼承的是FragmentActivity)
//所以調用的是getSupport...方法,如果繼承Activity則直接調用get...方法
assertactionBar!=null;//這一句可以不理會,反正我是Ctrl+F1提示出來的,意思其實是判斷如果actionBar不為空則向下執行。
actionBar.hide();
注意:最後一點注意事項是:只支持Android API 21以上的手機
③ Android 將App的內容延伸到狀態欄/導航欄
來自我的CSDN博客: http://blog.csdn.net/dahaohan/article/details/52175190
看過Android的桌面應用都是介樣的:
如何讓自己的應用也達到這般效果呢?這里就介紹幾種常用的方法以及它們之間的區別。
首先展示下此次demo的布局和初始狀態:
初始效果圖如下:
使用這個方式首先要理解幾個概念,窗口層級以及窗口background/窗口透明:
Google在API-19 以及API-21新增對狀態欄/導航欄窗口透明和顏色的控制:
對應的在主題內即可控制:
這里首先要明了這里狀態欄和導航欄窗口是系統級窗口而Activity對應的時應用窗口,它們屬於不同的窗口層級;
然後狀態欄/導航欄系統級窗口是在App應用窗口之上,故而Activity應用窗口雖然有整個屏幕的大小,但是可顯示內容的區域得除去其上疊加的不透明的窗口區域。詳細的窗口計算繪制可參考大神老羅的博文:
Android窗口管理服務WindowManagerService計算Activity窗口大小的過程分析
下面來使用主題控制導航欄/狀態欄透明,同時看看上述兩種設置透明的方式效果有何不同:
初始桌面和啟動Activity效果圖:
可以看到雖然導航欄/狀態欄透明了,當時應用窗口顯示的內容依然只是除去了兩個系統窗口之外的區域,並沒有衍生到導航欄/狀態欄之下。
效果如下:
可以看到已經將應用的內容布局延伸到導航欄/狀態欄下方了,來看看關於android:windowTranslucentStatus
android:windowTranslucentNavigation的官方說明看看來理解其與設置color transparent的區別:
根據FLAG的說明,可以看出設置該標志位等同於View申請設置:
PS:從效果圖看,雖然布局延伸到狀態欄導航欄區域,但是相應的內容「hello world」文字也被狀態欄/導航欄遮住了。在布局根視圖設置fitsSystemWindows為true可以使得,系統自動為視圖添加一個狀態欄/導航欄高度的padding:
效果如下:
查看SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 和 SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN的說明,可以發現其實還有兩個非常接近的FLAG:
根據官方的說明提示,SYSTEM_UI_FLAG_FULLSCREEN / SYSTEM_UI_FLAG_HIDE_NAVIGATION主要用於動態切換隱藏/顯示系統導航欄/狀態欄;例如書籍閱讀應用/視頻播放應用等。而像游戲類的全屏應用則推薦使用window flag。
上述的透明導航欄/狀態欄等API基本是需要API-19或是API-21才能使用的,這里還有一種API-1的方案能夠實現布局內容全屏:
實際上只需要設置FLAG_LAYOUT_NO_LIMITS就足夠了;這FLAG是看Android原生的Launcher / Keyguard源碼,看到有用到如此設置,其窗口設置具體原理我也沒有弄清..... 有大神了解可以指點下。
PS:這個套路下,使用fitsSystemWindows="true"是無效的,智能自己控制號布局位置。
④ 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透明導航欄
在我的 UINavigationController 的子類,我使導航欄半透明: - (id)initWithRootViewController:(UIViewController *)rootViewController { if (self = [super initWithRootViewController:rootViewController]) { self.navigationBar.translucent = YES; } return self; } 色調顏色 在我的 UIApplicationDelegate 的子類,我設置導航欄中的色調顏色。我發現色調顏色的 alpha 沒有區別。也就是說,使用 alpha 0.1 不會導致要變得更透亮的欄。 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UINavigationBar appearance] setTintColor:[UIColor greenColor]]; } 邊緣 在我的內容視圖控制器中,我將設置邊緣為 UIRectEdgeNone 這樣頂部的導航欄不會砍。如果要使用默認的 UIRectEdgeAll ,導航欄將會永久地蓋頂部的我的內容。即使我要住在一起這種異常, UIRectEdgeAll 仍然不會啟用半透明效果。 - (void) viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; } 編輯: 試驗與邊緣 @rmaddy 在中所指出的廣告問題可能與 edgesForExtendedLayout。我發現綜合教程 edgesForExtendedLayout ,並試圖實現它: - (void) viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeAll; self. = YES; self. = NO; } 它不工作。首先,那裡是沒有半透明效果。第二,我的內容的頂部被切掉。在上面的代碼與以下示例頁上,神通最初由導航欄和它是很難向滾動。你可以拉下,看到頂部的化身,但當你放開,頁面會自動彈起來,神通將會再次被遮掩。 解決方法 1: 問題是由第三方拉下來刷新視圖EGORefreshTableHeaderView,而普遍地使用了之前的 iOS 6 介紹系統刷新控制引起的。 這種觀點混淆了 iOS 7,讓它認為內容是比真的很高。Ios 6 和 7,我已經有條件地切換到使用UIRefreshControl。現在的導航欄不會砍掉我的內容。我可以使用 UIRectEdgeAll ,使我下面的導航欄的內容走。最後,顯示我的導航欄與較低的 α 要獲得半透明效果色調圖。 // mostly rendant calls, because they're all default self.edgesForExtendedLayout = UIRectEdgeAll; self. = YES; self. = NO; [[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.0 alpha:0.5]];