是否有可能把Android的动作条上的底部? [英] Is it possible to put Android ActionBar on the bottom?

查看:92
本文介绍了是否有可能把Android的动作条上的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序的Andr​​oid平板(XOOM),我想知道这是否是possile把操作栏在屏幕的底部,而不是顶部(这是默认选项)

i'm developing an application to an Android Tablet (XOOM), and i would like to know if it is possile to put the action bar on the bottom of the screen, instead of the top (which is the default option).

感谢。

推荐答案

是的,它有可能是这样,试试这个。

Yes it is possible like this,try this.

 public void setActionBArAtBottom(View layoutView, Intent intent,
            Context context, ContentValues componentIds) throws Exception {
        if (componentIds != null) {
            setValues(componentIds);
        } else {
            System.out
                    .println("Provide appropriate information to set ActionBar at bottom");
            try {
                throw new UnsufficientResourcesException();
            } catch (UnsufficientResourcesException e) {
                e.printStackTrace();
            }
        }
        // getting the parent of screen..actually this is the child of root
        // parent...
        ViewGroup screenParent = (ViewGroup) layoutView.getParent().getParent();
        // now getting actionbarview...as follows...
        View actionBArView = ((ViewGroup) screenParent.getChildAt(0))
                .getChildAt(0);
        // now getting framelayout that is custom layout to display actionbar at
        // the bottom...
        FrameLayout customActionBarFrameLayout = (FrameLayout) layoutView
                .findViewById(BOTTOM_ACTION_BAR_LAYOUT_ID);
        // now remove actionbarView from its parent view...
        ViewGroup actionBarViewParent = removeFromParent(actionBArView);
        removeTitleAndIcon((ViewGroup) actionBArView);
        // now setting actionbar view to the framlayout...
        customActionBarFrameLayout.addView(actionBArView);

        // get the custombar layout....
        View customTitleBarLayout = LayoutInflater.from(context).inflate(
                NEW_TITLE_BAR_LAYOUT, null);
        // setting icon to titile bar...
        ((ImageView) customTitleBarLayout.findViewById(NEW_TITLE_ICON__ID))
                .setImageDrawable(getActivityIcon(intent, context));
        // setting title...
        ((TextView) customTitleBarLayout.findViewById(NEW_TITLE_ID))
                .setText(((SherlockActivity) context).getTitle());
        // now set this layout to
        actionBarViewParent.addView(customTitleBarLayout);

    }

    // method use to remove child from its parent...
    private ViewGroup removeFromParent(View child) {
        // removing child...
        ViewGroup parentGroup = (ViewGroup) child.getParent();
        parentGroup.removeView(child);
        return parentGroup;
    }

    // this method will set application icon to custom title bar layout...
    private Drawable getActivityIcon(Intent intent, Context context) {
        // getting the current activity icon set...
        Drawable drawable = null;
        try {
            drawable = context.getPackageManager().getActivityIcon(intent);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return drawable;
    }

    // remove title and icon from bottombar...
    private void removeTitleAndIcon(ViewGroup actionBarViewGroup) {
        actionBarViewGroup.removeAllViews();
    }

    private void setValues(ContentValues contentValues) throws Exception {
        try {
            BOTTOM_ACTION_BAR_LAYOUT_ID = contentValues
                    .getAsInteger(BOTTOM_ACTION_BAR_FRAME_LAYOUT_ID);
            NEW_TITLE_BAR_LAYOUT = contentValues
                    .getAsInteger(NEW_TITLE_BAR_LAYOUT_ID);
            NEW_TITLE_ICON__ID = contentValues
                    .getAsInteger(NEW_TITLE_ICON_IMAGEVIEW_ID);
            NEW_TITLE_ID = contentValues.getAsInteger(NEW_TITLE_VIEW_ID);
        } catch (Exception e) {

            throw new UnsufficientResourcesException();

        }
    }
}

这篇关于是否有可能把Android的动作条上的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆