[Android UI]ActionBar随ScorllView上下拖动而透明度渐变效果(续1)

根据上一篇ActionBar随ScorllView上下拖动而透明度渐变效果的基本描述,我们自定义的actionbar滚动透明的效果使用起来可能有点繁琐。这次想要在上次的代码内容上(可自动切换、无限滑动的图片广告展示栏的实现分享(续1)),博主太懒了,哈哈,实现这样的效果。

这次的demo很简单,老样子,你可以自己下载demo稍微看看,结构如下:

主界面代码:

package org.jan.adviewpaper.demo;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.achep.header2actionbar.FadingActionBarHelper;
/**
 * demo 主界面
 * @author jan
 */
public class MainActivity extends Activity implements OnClickListener {

	private static final String TAG = "MainActivity";
	private ActionBar mActionBar;
	//这边的是ActionBar的辅助类,设置透明度在里面的干活!
	private FadingActionBarHelper mFadingActionBarHelper;
	private Button mSearchButton;
	//....

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mActionBar = getActionBar();
		// 使用自定义的布局的ActionBar
		mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		mActionBar.setCustomView(R.layout.my_actionbar);
		mSearchButton = (Button) mActionBar.getCustomView().findViewById(
				R.id.search_button);
		// 给搜索按钮添加点击事件
		mSearchButton.setOnClickListener(this);
		// 注意!定义Actionbar的背景色 ,这句不能忘记!
		mActionBar.getCustomView().setBackground(
				getResources().getDrawable(R.drawable.actionbar_bg));
		mFadingActionBarHelper = new FadingActionBarHelper(getActionBar(),
				getResources().getDrawable(R.drawable.actionbar_bg));
		if (savedInstanceState == null) {
			getFragmentManager().beginTransaction()
					.add(R.id.container_view, new MyViewFragment()).commit();
		}
	}

	public FadingActionBarHelper getFadingActionBarHelper() {
		return mFadingActionBarHelper;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.search_button:
			Log.d(TAG, "你点击了搜索按钮!");
			Toast.makeText(this, "you clicked search", 1000).show();
			break;
		}
	}
}

必须继承这个抽象类来实现效果HeaderFragment.java:

public abstract class HeaderFragment extends Fragment {

    private static final String TAG = "HeaderFragment";

    public static final int HEADER_BACKGROUND_SCROLL_NORMAL = 0;
    public static final int HEADER_BACKGROUND_SCROLL_PARALLAX = 1;
    public static final int HEADER_BACKGROUND_SCROLL_STATIC = 2;
    //TODO header’s height 你可以改变他
    public static int headerHeight=350;
    private FrameLayout mFrameLayout;
    private View mContentOverlay;

    // header
    private View mHeader;
    private View mHeaderHeader;
    private View mHeaderBackground;
    private int mHeaderHeight;
    private int mHeaderScroll;

    private int mHeaderBackgroundScrollMode = HEADER_BACKGROUND_SCROLL_NORMAL;

    private Space mFakeHeader;
    private boolean isListViewEmpty;

    // listeners
    private AbsListView.OnScrollListener mOnScrollListener;
    private OnHeaderScrollChangedListener mOnHeaderScrollChangedListener;

    public interface OnHeaderScrollChangedListener {
        public void onHeaderScrollChanged(float progress, int height, int scroll);
    }

    public void setOnHeaderScrollChangedListener(OnHeaderScrollChangedListener listener) {
        mOnHeaderScrollChangedListener = listener;
    }

    public void setHeaderBackgroundScrollMode(int scrollMode) {
        mHeaderBackgroundScrollMode = scrollMode;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final Activity activity = getActivity();
        assert activity != null;
        mFrameLayout = new FrameLayout(activity);

        mHeader = onCreateHeaderView(inflater, mFrameLayout);
        mHeaderHeader = mHeader.findViewById(android.R.id.title);
//        mHeaderBackground = mHeader.findViewById(android.R.id.background);
        assert mHeader.getLayoutParams() != null;
//        mHeaderHeight = mHeader.getLayoutParams().height;
        View content = onCreateContentView(inflater, mFrameLayout);
        mHeaderHeight = headerHeight;
        mFakeHeader = new Space(activity);
        mFakeHeader.setLayoutParams(
                new ListView.LayoutParams(0, mHeaderHeight));
        mFakeHeader.setLayoutParams(
                new ListView.LayoutParams(0, 0));

        mHeaderBackground = content.findViewById(android.R.id.background);
        if (content instanceof ListView) {
            isListViewEmpty = true;

            final ListView listView = (ListView) content;
            listView.addHeaderView(mFakeHeader);
            listView.setOnScrollListener(new AbsListView.OnScrollListener() {

                @Override
                public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                    if (mOnScrollListener != null) {
                        mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                    }
                }

                @Override
                public void onScroll(AbsListView absListView, int firstVisibleItem,
                                     int visibleItemCount, int totalItemCount) {
                    if (mOnScrollListener != null) {
                        mOnScrollListener.onScroll(
                                absListView, firstVisibleItem,
                                visibleItemCount, totalItemCount);
                    }

                    if (isListViewEmpty) {
                        scrollHeaderTo(0);
                    } else {
                        final View child = absListView.getChildAt(0);
                        assert child != null;
                        scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                    }
                }
            });
        } else {

            // Merge fake header view and content view.
            final LinearLayout view = new LinearLayout(activity);
            view.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            view.setOrientation(LinearLayout.VERTICAL);
            view.addView(mFakeHeader);
            view.addView(content);

            // Put merged content to ScrollView
            final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
            scrollView.addView(view);
            scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
                @Override
                public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                    scrollHeaderTo(-t);
                }
            });
            content = scrollView;
        }

        mFrameLayout.addView(content);
        mFrameLayout.addView(mHeader);

        // Content overlay view always shows at the top of content.
        if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
            mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
        }

        // Post initial scroll
        mFrameLayout.post(new Runnable() {
            @Override
            public void run() {
                scrollHeaderTo(0, true);
            }
        });

        return mFrameLayout;
    }

    private void scrollHeaderTo(int scrollTo) {
        scrollHeaderTo(scrollTo, false);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void scrollHeaderTo(int scrollTo, boolean forceChange) {
        scrollTo = Math.min(Math.max(scrollTo, -mHeaderHeight), 0);
        if (mHeaderScroll == (mHeaderScroll = scrollTo) & !forceChange) return;

        setViewTranslationY(mHeader, scrollTo);
        setViewTranslationY(mHeaderHeader, -scrollTo);

        switch (mHeaderBackgroundScrollMode) {
            case HEADER_BACKGROUND_SCROLL_NORMAL:
                setViewTranslationY(mHeaderBackground, 0);
                break;
            case HEADER_BACKGROUND_SCROLL_PARALLAX:
                setViewTranslationY(mHeaderBackground, -scrollTo / 1.6f);
                break;
            case HEADER_BACKGROUND_SCROLL_STATIC:
                setViewTranslationY(mHeaderBackground, -scrollTo);
                break;
        }

        if (mContentOverlay != null) {
            final ViewGroup.LayoutParams lp = mContentOverlay.getLayoutParams();
            final int delta = mHeaderHeight + scrollTo;
            lp.height = mFrameLayout.getHeight() - delta;
            mContentOverlay.setLayoutParams(lp);
            mContentOverlay.setTranslationY(delta);
        }

        notifyOnHeaderScrollChangeListener(
                (float) -scrollTo / mHeaderHeight,
                mHeaderHeight,
                -scrollTo);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setViewTranslationY(View view, float translationY) {
        if (view != null) view.setTranslationY(translationY);
    }

    private void notifyOnHeaderScrollChangeListener(float progress, int height, int scroll) {
        if (mOnHeaderScrollChangedListener != null) {
            mOnHeaderScrollChangedListener.onHeaderScrollChanged(progress, height, scroll);
        }
    }

    public abstract View onCreateHeaderView(LayoutInflater inflater, ViewGroup container);

    public abstract View onCreateContentView(LayoutInflater inflater, ViewGroup container);

    public abstract View onCreateContentOverlayView(LayoutInflater inflater, ViewGroup container);

    public void setListViewAdapter(ListView listView, ListAdapter adapter) {
        isListViewEmpty = adapter == null;
        listView.setAdapter(null);
        listView.removeHeaderView(mFakeHeader);
        listView.addHeaderView(mFakeHeader);
        listView.setAdapter(adapter);
    }

    /**
     * {@inheritDoc AbsListView#setOnScrollChangedListener}
     */
    public void setListViewOnScrollChangedListener(AbsListView.OnScrollListener listener) {
        mOnScrollListener = listener;
    }

    // //////////////////////////////////////////
    // //////////// -- GETTERS -- ///////////////
    // //////////////////////////////////////////

    public View getHeaderView() {
        return mHeader;
    }

    public View getHeaderHeaderView() {
        return mHeaderHeader;
    }

    public View getHeaderBackgroundView() {
        return mHeaderBackground;
    }

    public int getHeaderBackgroundScrollMode() {
        return mHeaderBackgroundScrollMode;
    }

}

FadingActionBarHelper.java

public class FadingActionBarHelper {

    private static final String TAG = "FadingActionBarHelper";
    //默认的透明度最大值(255)
    private static final int MAX_ALPHA = 220;
    private int mAlpha = 255;
    private Drawable mDrawable;
    private boolean isAlphaLocked;

    private final ActionBar mActionBar;

    public FadingActionBarHelper(final ActionBar actionBar) {
        mActionBar = actionBar;
    }

    public FadingActionBarHelper(final ActionBar actionBar, final Drawable drawable) {
        mActionBar = actionBar;
        setActionBarBackgroundDrawable(drawable);
    }

    public void setActionBarBackgroundDrawable(Drawable drawable) {
        setActionBarBackgroundDrawable(drawable, true);
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
	public void setActionBarBackgroundDrawable(Drawable drawable, boolean mutate) {
        mDrawable = mutate ? drawable.mutate() : drawable;
        mActionBar.setBackgroundDrawable(mDrawable);

        if (mAlpha == MAX_ALPHA) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                mAlpha = mDrawable.getAlpha();
        } else {
            setActionBarAlpha(mAlpha);
        }
    }

    /**
     * An {@link android.app.ActionBar} background drawable.
     *
     * @see #setActionBarBackgroundDrawable(android.graphics.drawable.Drawable)
     * @see #setActionBarAlpha(int)
     */
    public Drawable getActionBarBackgroundDrawable() {
        return mDrawable;
    }

    /**
     * Please use this method for global changes only!
     * This is helpful when you need to provide something like
     * Navigation drawer: lock ActionBar and set
     * {@link android.graphics.drawable.Drawable#setAlpha(int)}
     * to {@link #getActionBarBackgroundDrawable()} directly.
     *
     * @param alpha a value from 0 to 255
     * @see #getActionBarBackgroundDrawable()
     * @see #getActionBarAlpha()
     */
    public void setActionBarAlpha(int alpha) {
        if (mDrawable == null) {
            Log.w(TAG, "Set action bar background before setting the alpha level!");
            return;
        }
        if (!isAlphaLocked){
        	mDrawable.setAlpha(alpha);
        	View view = mActionBar.getCustomView();
			if(view!=null){
				//这里是对自定义actionbar的其他控件背景的处理,我这边就草草了事了
				if(alpha>=55){
					view.findViewById(R.id.search_button).setBackgroundResource(R.drawable.search);
					view.findViewById(R.id.refresh_button).setBackgroundResource(R.drawable.refresh);
				}else{
					view.findViewById(R.id.search_button).setBackgroundResource(R.drawable.skin_nav_icon_l_search_rev);
					view.findViewById(R.id.refresh_button).setBackgroundResource(R.drawable.skin_nav_icon_r_refresh_rev);
				}
				//注意!这边是真正设置背景透明度的地方
				if(view.getBackground()!=null&&alpha<=MAX_ALPHA){
					view.getBackground().setAlpha(alpha);
				}
			}
        }
        mAlpha = alpha;
    }

    public int getActionBarAlpha() {
        return mAlpha;
    }

    /**
     * When ActionBar's alpha is locked {@link #setActionBarAlpha(int)}
     * won't change drawable\'s alpha (but will change {@link #getActionBarAlpha()} level)
     *
     * @param lock
     */
    public void setActionBarAlphaLocked(boolean lock) {

        // Update alpha level on unlock
        if (isAlphaLocked != (isAlphaLocked = lock) && !isAlphaLocked) {
            setActionBarAlpha(mAlpha);
        }
    }

    public boolean isActionBarAlphaLocked() {
        return isAlphaLocked;
    }
}

我们主要内容MyViewFragment.java

public class MyViewFragment extends HeaderFragment {

    private FrameLayout mContentOverlay;
    private static final String TAG = "MyViewFragment";
    private static int PAGER_START_PLAY = 0x123;
	// 切换间隔时间3秒
	private static final int PLAY_TIME = 3 * 1000;
	// 实现viewpager的控件
	private JazzyViewPager mViewPaper;
	// 圆形标签的父层
	private LinearLayout symbolContainer;
	private ImageView[] images;
	private ImageView[] circleSymbols;
	private ArrayList<String> imageUrlList;
	// 图片框架universalimageloader的图形帮助类
	private ImageLoader mImageLoader;
	private Handler mHandler;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        setHeaderBackgroundScrollMode(HEADER_BACKGROUND_SCROLL_PARALLAX);
        //注意!这个是很屌的方法,用来改变actionbar的透明度
        setOnHeaderScrollChangedListener(new OnHeaderScrollChangedListener() {
            @Override
            public void onHeaderScrollChanged(float progress, int height, int scroll) {
                height -= getActivity().getActionBar().getHeight();
                progress = (float) scroll / height;
                if (progress > 1f) progress = 1f;
                progress = (1 - (float) Math.cos(progress * Math.PI)) * 0.5f;
                ((MainActivity) getActivity())
                        .getFadingActionBarHelper()
                        .setActionBarAlpha((int) (255 * progress));
            }
        });
		mImageLoader = ImageLoader.getInstance();
		initMockImages();

    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public View onCreateHeaderView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_header, container, false);
    }

    @Override
    public View onCreateContentView(LayoutInflater inflater, ViewGroup container) {
        View view  =  inflater.inflate(R.layout.fragment_myview, container, false);
		setupMyHandler();
		initViews(view);
        return view;
    }

    @Override
    public View onCreateContentOverlayView(LayoutInflater inflater, ViewGroup container) {
//        ProgressBar progressBar = new ProgressBar(getActivity());
        mContentOverlay = new FrameLayout(getActivity());
//        mContentOverlay.addView(progressBar, new FrameLayout.LayoutParams(
//                ViewGroup.LayoutParams.WRAP_CONTENT,
//                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
//        if (mLoaded) mContentOverlay.setVisibility(View.GONE);
        return mContentOverlay;
    }

    private void setupMyHandler() {
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				if (PAGER_START_PLAY == msg.what) {
					Log.d(TAG, "----PAGER_START_PLAY-----");
					int current = mViewPaper.getCurrentItem();
					if (current == images.length - 1) {
						current = -1;
					}
					Log.d(TAG, "play item = " + current);
					mViewPaper.setCurrentItem(current + 1);
					mHandler.sendEmptyMessageDelayed(PAGER_START_PLAY,
							PLAY_TIME);
				}
			}
		};
	}

	private void initViews(View v) {
		symbolContainer = (LinearLayout) v.findViewById(R.id.symblo_container);
		circleSymbols = new ImageView[imageUrlList.size()];
		images = new ImageView[imageUrlList.size()];
		for (int i = 0; i < imageUrlList.size(); i++) {
			ImageView imageView = new ImageView(getActivity());
			ImageView circle = new ImageView(getActivity());
			imageView.setScaleType(ScaleType.CENTER_CROP);
			images[i] = imageView;
			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			lp.setMargins(3, 0, 3, 0);
			circle.setLayoutParams(lp);
			circle.setTag(i);
			circle.setBackgroundDrawable(getResources().getDrawable(
					R.drawable.circle_normal));
			circleSymbols[i] = circle;
			symbolContainer.addView(circleSymbols[i]);
		}
		setViewPager(v,TransitionEffect.Standard);
	}

	private void setViewPager(View v,TransitionEffect effect) {
		mViewPaper = (JazzyViewPager) v.findViewById(R.id.adviewpaper);
		mViewPaper.setTransitionEffect(effect);
		mViewPaper.setAdapter(new MyPagerAdapter());
		mViewPaper.setOnPageChangeListener(new MyPageViewChangeListener());
		mViewPaper.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (imageUrlList.size() == 0 || imageUrlList.size() == 1) {
					return true;
				} else {
					return false;
				}
			}
		});
		circleSymbols[0].setBackgroundDrawable(getResources().getDrawable(
				R.drawable.circle_selected));
		mViewPaper.setCurrentItem(0);
		mHandler.sendEmptyMessageDelayed(PAGER_START_PLAY, PLAY_TIME);
	}

	/**
	 * 创建本地图片数据
	 */
	private void initMockImages() {
		imageUrlList = new ArrayList<String>();
		imageUrlList.add("drawable://" + R.drawable.jd_ad_0);
		imageUrlList.add("drawable://" + R.drawable.jd_ad_1);
		imageUrlList.add("drawable://" + R.drawable.jd_ad_2);
		imageUrlList.add("drawable://" + R.drawable.jd_ad_3);
		imageUrlList.add("drawable://" + R.drawable.jd_ad_4);
	}

	/**
	 * 设置圆形标签的状态
	 *
	 * @param index
	 *            当前标签的位置
	 */
	private void setSymbolImages(int index) {
		for (ImageView image : circleSymbols) {
			Integer i = (Integer) image.getTag();
			if (i == index) {
				image.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.circle_selected));
			} else {
				image.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.circle_normal));
			}
		}
	}
	private class MyPagerAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return imageUrlList.size();
		}

		@Override
		public boolean isViewFromObject(View view, Object obj) {
			if (view instanceof OutlineContainer) {
				return ((OutlineContainer) view).getChildAt(0) == obj;
			} else {
				return view == obj;
			}
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			((ViewPager) container).removeView(mViewPaper
					.findViewFromObject(position));
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			mImageLoader.displayImage(imageUrlList.get(position),
					images[position]);
			container.addView(images[position], LayoutParams.MATCH_PARENT,
					LayoutParams.MATCH_PARENT);
			final int index = position;
			images[position].setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Log.e(TAG, "you clicked images position is" + index);
					Toast.makeText(getActivity(),
							"你点击了第" + (index + 1) + "张图", Toast.LENGTH_SHORT)
							.show();
				}
			});
			// 注意!不加这个方法要报IllegalStateException
			mViewPaper.setObjectForPosition(images[position], position);
			return images[position];
		}

	}

	private class MyPageViewChangeListener implements OnPageChangeListener {

		@Override
		public void onPageScrollStateChanged(int stateCode) {
			switch (stateCode) {
			case 0:
				// 你什么都没动
				break;
			case 1:
				// 正在滑动哦
				break;
			case 2:
				// 滑动完了
				break;
			}
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageSelected(int position) {
			Log.d(TAG, "onPageSelected-->position:" + position);
			setSymbolImages(position);
		}
	}

}

好了。demo的下载连接:点击打开链接

时间: 2024-10-31 16:46:28

[Android UI]ActionBar随ScorllView上下拖动而透明度渐变效果(续1)的相关文章

[Android UI]ActionBar随ScorllView上下拖动而透明度渐变效果

我看到越来越多的应用使用这样的效果,如QQ空间5.0的主界面,确实很好看!大概就搜了一下相关的实现方式,发现早就有了相关的方案: 仿QQ空间滚动ActionBar透明度变化Demo 还有我在github上看到就有这样的实现方式,这也是本博文的主要核心内容: 具体请查看:https://github.com/AChep/Header2ActionBar 效果如下: 这是Demo结构: 1.FadingActionBarHelper.java 这个类是处理Actionbar的核心类,处理对scrol

[Android UI] ActionBar 自定义属性

actionbar 默认放在顶部, 如果在application或者activity中加入 android:uiOptions="splitActionBarWhenNarrow" 那么,actionbar将在底部显示. 自定义属性,包括自定义actionbar的背景颜色 <!-- the theme applied to the application or activity --> <style name="CustomActivityTheme&quo

【Android UI设计与开发】8.顶部标题栏(一)ActionBar 奥义&#183;详解

原文地址:http://www.cnblogs.com/yc-755909659/p/4290784.html 一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和menu,在程序运行中一直置于顶部,对于Android平板设备来说屏幕更大它的标题使用Action Bar来设计可以展示更多丰富的内容,方便操控. 二.ActionBar的功能 用图的方式来讲解

【Android UI设计与开发】顶部标题栏(一)ActionBar 奥义&#183;详解

转自:http://www.cnblogs.com/yc-755909659/p/4290784.html 一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和menu,在程序运行中一直置于顶部,对于Android平板设备来说屏幕更大它的标题使用Action Bar来设计可以展示更多丰富的内容,方便操控. 二.ActionBar的功能 用图的方式来讲解它的

Android UI之Tab(ActionBar+Fragment实现)

Fragment和ActionBar都是Android3.0之后出现的,Fragment,碎片,主要是为了支持更多的UI设计在大屏幕设备上,如平板.因为现在设备的屏幕越来越大,使用Fragment可以更灵活的管理视图层次的变化.像Activity一样,可以创建Fragment来包含View,进行布局,但是Fragment必须嵌入在Activity中,不能单独存在,而且一个Activity可以嵌入多个Fragment,同时一个Fragment可以被多个Activity重用.Action Bar被认

Android UI开发详解之ActionBar .

在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果. 一.添加ActionBar 1.不需要导入ActionBar,因为在android3.0或者以上版本中,ActionBar已经默认的包含在Activity中2.在Android3.0的默认主题“holographic”中,已经创造了ActionBar3.当android:minSdkVersion 或者 an

【Android UI设计与开发】第12期:顶部标题栏(三)ActionBar实现层级导航的返回效果

转载请注明出处: http://blog.csdn.net/yangyu20121224/article/details/9059459       今天我们继续来讲解ActionBar的使用,不清楚这个类的读者可以翻阅博主前几篇的文章或者在网络上查阅相关 的资料,关于这个类讲解的文章还是很多的,功能确实也很强大.好的,话不多说,让我们赶快进入正题吧. 一.使用应用图标实现层级导航 在默认的情况下,应用程序图标显示在操作栏的左边.你能够把这个图标当做操作项来使用,应用程序可以在这 个图标上响应以

【Android UI设计与开发】第13期:顶部标题栏(四)自定义ActionBar风格和样式

转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9087941   这篇文章将对ActionBar专题前面几篇学习过的内容做一个总结,顺便运用以前学过的知识实现一个自定义样式的ActionBar标题栏效果.话不多说,进入今天的正题. 一.实现效果图 竖屏效果图:最左边是Logo图标,右边是工具栏按钮,点击Menu键显示其余的按钮键,下方是Tab标签选项. 横屏效果图:竖屏中的Tab选项标签变成了中间的下拉导航按钮 二.项目结

【Android UI设计与开发】之详解ActionBar的使用

详解Android中的ActionBar的使用 请尊重他人的劳动成果,转载请注明出处:详解Android中的ActionBar的使用 http://blog.csdn.net/fengyuzhengfan/article/details/40216389 ActionBar是Android 3.0(API level 11)引入的一个新控件,它代表了应用程序标题栏,如果要开发兼容的程序,可以使用v7包下的ActionBar.我们在应用中看见的ActionBar一般是下图的样子,比如有道词典及微信