当前位置:首页 » 安卓系统 » android侧边栏

android侧边栏

发布时间: 2022-02-14 16:45:26

Ⅰ 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 侧边栏如何覆盖actionbar

Tab可以设置自定义的View,Actionbar上也可以设置自定义的View.
1//Actionbar Tab设置自定义组件
2getActionBar().newTab().setCustomView();
3//ActionBar 设置自定义组件
4LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
5View customNav = LayoutInflater.from(this).inflate
6(R.layout.img, null); // layout which contains your button.

actionBar.setCustomView(customNav, lp);
7actionBar.setDisplayShowCustomEnabled(true);

Ⅲ Android侧边栏遮盖住了ToolBar

让侧边栏的布局(找android:layout_gravity="start"有这个的就是侧边的布局),可以把他放在ToolBar的下边,具体看你外部总布局,是什么布局。最简单的就是,侧边栏的布局android:layout_marginTop="ToolBar的高度",还不行,你把布局文件贴出来,我看看

Ⅳ 安卓侧边栏app,(最好是中文)

魅族那边有个Mdock很不错的。

Ⅳ 不小心把android studio的预览从右边侧边栏删去了,怎么重新显示出来

View->Tool Windows->Preview 可以找回。

Ⅵ android中侧边栏怎么实现

android中侧边栏 都是使用了一下开源框架
叫SlidingMenu 可以设置左右侧边,具体查看api吧

Ⅶ 有没有android 实现仿人人的侧边栏的demo啊 求学习

这个是github上非常流行的project。网址是: https://github.com/jfeinstein10/SlidingMenu
直接运行的Demo是: https://play.google.com/store/apps/details?id=com.slidingmenu.example

Ⅷ android studio 侧边栏怎么打开

最左侧有几个竖着的单词,Project, Structure单击这几个按钮就可以打开了
或者在菜单View->Tools->Project这打开

Ⅸ android studio 左右两边导航栏怎么点出来

打开AndroidStudio工具,点击“设置”按钮,如图:

左侧导航栏,选择“Editor”,如图:

右面往下拉鼠标,直到最后,找到“show quick doc……”如图:

打上对勾,选择apply ,点击OK,如图:

进入代码,将鼠标移上去,就会看到悬浮提示窗口,如图:

Ⅹ Android Studio左侧Project侧边栏如何设置默认显示的是Project

很多Android Stuio初学者可能会一不小心把左边的Project栏给关了,结果发现找很久也没找到怎么再打

热点内容
rsa加密c源代码 发布:2025-03-15 19:53:55 浏览:692
linux解压bin 发布:2025-03-15 19:40:25 浏览:383
存储数据为什么只能使用两种状态 发布:2025-03-15 19:40:21 浏览:263
平方的运算法则 发布:2025-03-15 19:38:57 浏览:970
江苏省苏州市社保卡初始登录密码是多少 发布:2025-03-15 19:38:55 浏览:515
安卓主板哪里有卖 发布:2025-03-15 19:26:10 浏览:31
Q9源码 发布:2025-03-15 19:24:21 浏览:177
芬兰编程教育 发布:2025-03-15 18:59:46 浏览:427
因特网的服务器地址 发布:2025-03-15 18:53:01 浏览:893
手机实体店什么配置好 发布:2025-03-15 18:32:35 浏览:170