android.app.Activity.getActionBar()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(205)

本文整理了Java中android.app.Activity.getActionBar()方法的一些代码示例,展示了Activity.getActionBar()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getActionBar()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getActionBar

Activity.getActionBar介绍

暂无

代码示例

代码示例来源:origin: joyoyao/superCleanMaster

protected void setActionBarDescription() {
  if (mActivity != null && mActivity.getActionBar() != null) {
    try {
      Method setHomeActionContentDescription = ActionBar.class.getDeclaredMethod(
        "setHomeActionContentDescription", Integer.TYPE);
      setHomeActionContentDescription.invoke(mActivity.getActionBar(),
        mDrawerLayout.isDrawerOpen(GravityCompat.START) ? mOpenDrawerContentDescRes : mCloseDrawerContentDescRes);
      if (Build.VERSION.SDK_INT <= 19) {
        mActivity.getActionBar().setSubtitle(mActivity.getActionBar().getSubtitle());
      }
    } catch (Exception e) {
      Log.e(TAG, "setActionBarUpIndicator", e);
    }
  }
}

代码示例来源:origin: zwwill/yanxuan-weex-demo

private static int getSmartBarHeight(Activity activity) {
  ActionBar actionbar = activity.getActionBar();
  if (actionbar != null)
    try {
      Class c = Class.forName("com.android.internal.R$dimen");
      Object obj = c.newInstance();
      Field field = c.getField("mz_action_button_min_height");
      int height = Integer.parseInt(field.get(obj).toString());
      return activity.getResources().getDimensionPixelSize(height);
    } catch (Exception e) {
      e.printStackTrace();
      actionbar.getHeight();
    }
  return 0;
}

代码示例来源:origin: seven332/EhViewer

protected void onSystemUiShown() {
  ActionBar ab = mActivity.getActionBar();
  if (ab != null) {
    ab.show();
  }
  mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setIsShowing(true);
}

代码示例来源:origin: seven332/EhViewer

protected void onSystemUiHidden() {
  ActionBar ab = mActivity.getActionBar();
  if (ab != null) {
    ab.hide();
  }
  mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setIsShowing(false);
}

代码示例来源:origin: joyoyao/superCleanMaster

protected void setActionBarUpIndicator() {
  if (mActivity != null) {
    try {
      Method setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator",
        Drawable.class);
      setHomeAsUpIndicator.invoke(mActivity.getActionBar(), mDrawerImage);
      return;
    } catch (Exception e) {
     //   Log.e(TAG, "setActionBarUpIndicator error", e);
    }
    final View home = mActivity.findViewById(android.R.id.home);
    if (home == null) {
      return;
    }
    final ViewGroup parent = (ViewGroup) home.getParent();
    final int childCount = parent.getChildCount();
    if (childCount != 2) {
      return;
    }
    final View first = parent.getChildAt(0);
    final View second = parent.getChildAt(1);
    final View up = first.getId() == android.R.id.home ? second : first;
    if (up instanceof ImageView) {
      ImageView upV = (ImageView) up;
      upV.setImageDrawable(mDrawerImage);
    }
  }
}

代码示例来源:origin: seven332/EhViewer

@Override
protected void onSystemUiShown() {
  if (mLevel == SystemUiHelper.LEVEL_LOW_PROFILE) {
    // Manually show the action bar when in low profile mode.
    ActionBar ab = mActivity.getActionBar();
    if (ab != null) {
      ab.show();
    }
  }
  setIsShowing(true);
}

代码示例来源:origin: seven332/EhViewer

@Override
  protected void onSystemUiHidden() {
    if (mLevel == SystemUiHelper.LEVEL_LOW_PROFILE) {
      // Manually hide the action bar when in low profile mode.
      ActionBar ab = mActivity.getActionBar();
      if (ab != null) {
        ab.hide();
      }
    }

    setIsShowing(false);
  }
}

代码示例来源:origin: zwwill/yanxuan-weex-demo

public static int getDisplayHeight(Activity activity) {
  int height = 0;
  if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) {
    Point point=new Point();
    activity.getWindowManager().getDefaultDisplay().getSize(point);
    height=point.y;
  }
  Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar);
  if (isSupportSmartBar) {
    int smartBarHeight = getSmartBarHeight(activity);
    Log.e(TAG, "smartBarHeight:" + smartBarHeight);
    height -= smartBarHeight;
  }
  if (activity != null && activity.getActionBar() != null) {
   int actionbar= activity.getActionBar().getHeight();
   if(actionbar==0){
    TypedArray actionbarSizeTypedArray=activity.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize});
    actionbar= (int) actionbarSizeTypedArray.getDimension(0,0);
   }
   Log.d(TAG, "actionbar:" + actionbar);
   height -= actionbar;
  }
  int status = getStatusBarHeight(activity);
  Log.d(TAG, "status:" + status);
  height -= status;
  Log.d(TAG,"height:"+height);
  return height;
}

代码示例来源:origin: joyoyao/superCleanMaster

@Override
public void onActivityCreated(Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);
  getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
  getActivity().getActionBar().setDisplayShowHomeEnabled(false);
  getActivity().getActionBar().setTitle(
      "Информация о версии");
}

代码示例来源:origin: Neamar/KISS

public static void updateThemePrimaryColor(Activity activity) {
  int notificationBarColorOverride = getNotificationBarColor(activity);
  // Circuit breaker, keep default behavior.
  if (notificationBarColorOverride == COLOR_DEFAULT) {
    return;
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = activity.getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    // Update status bar color
    window.setStatusBarColor(notificationBarColorOverride);
  }
  ActionBar actionBar = activity.getActionBar();
  if (actionBar != null) {
    actionBar.setBackgroundDrawable(new ColorDrawable(notificationBarColorOverride));
  }
}

代码示例来源:origin: JessYanCoding/ArmsComponent

@Override
public void onActivityStarted(Activity activity) {
  Timber.i(activity + " - onActivityStarted");
  if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) {
    //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行
    //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行
    activity.getIntent().putExtra("isInitToolbar", true);
    //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar") != null) {
      if (activity instanceof AppCompatActivity) {
        ((AppCompatActivity) activity).setSupportActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
        ((AppCompatActivity) activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
      } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
          activity.setActionBar(ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar"));
          activity.getActionBar().setDisplayShowTitleEnabled(false);
        }
      }
    }
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title") != null) {
      ((TextView) ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_title")).setText(activity.getTitle());
    }
    if (ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back") != null) {
      ArmsUtils.findViewByName(activity.getApplicationContext(), activity, "public_toolbar_back").setOnClickListener(v -> {
        activity.onBackPressed();
      });
    }
  }
}

代码示例来源:origin: weexteam/weex-hackernews

android.app.ActionBar actionbar = ((Activity) mWXSDKInstance.getContext()).getActionBar();
if (actionbar != null) {
  switch (visibility) {

代码示例来源:origin: stackoverflow.com

@Override
public void onActivityCreated(Bundle savedInstanceState) {
  Activity activity = getActivity();
  activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
  @Override
    public void onMenuVisibilityChanged(boolean isVisible) {
      // TODO Auto-generated method stub
      //you can check the isVisible boolean to check
      // if the overFlowMenu is visible or not
    }
  });

代码示例来源:origin: stackoverflow.com

public boolean isOverflowMenuOpen  = false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
  Activity activity = getActivity();
  activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
  @Override
    public void onMenuVisibilityChanged(boolean isVisible) {
      // TODO Auto-generated method stub
      isOverflowMenuOpen = isOverflowMenuOpen ? false : true;
    }
  });

代码示例来源:origin: com.actionbarsherlock/actionbarsherlock

private void initActionBar() {
  if (mActionBar != null || mActivity.getActionBar() == null) {
    return;
  }
  mActionBar = new ActionBarWrapper(mActivity);
}

代码示例来源:origin: mapsforge/mapsforge

/**
 * Compatibility method.
 *
 * @param a the current activity
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void enableHome(Activity a) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    // Show the Up button in the action bar.
    a.getActionBar().setDisplayHomeAsUpEnabled(true);
  }
}

代码示例来源:origin: DreaminginCodeZH/SystemUiHelper

protected void onSystemUiHidden() {
  ActionBar ab = mActivity.getActionBar();
  if (ab != null) {
    ab.hide();
  }
  mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setIsShowing(false);
}

代码示例来源:origin: grzegorznittner/chanu

public GalleryActionBar(GalleryActivity activity) {
  mActionBar = ((Activity) activity).getActionBar();
  mContext = activity.getAndroidContext();
  mActivity = activity;
  mInflater = ((Activity) mActivity).getLayoutInflater();
  mCurrentIndex = 0;
}

代码示例来源:origin: qiubiteme/android_api_demos

@Override protected void onDetachedFromWindow() {
  super.onDetachedFromWindow();
  if (mAddedMenuListener) {
    mActivity.getActionBar().removeOnMenuVisibilityListener(this);
  }
}

代码示例来源:origin: pylerSM/XInstaller

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
             Bundle savedInstanceState) {
  super.onCreateView(inflater, parent, savedInstanceState);
  WebView v = new WebView(getActivity());
  ActionBar ab = getActivity().getActionBar();
  if (ab != null) {
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeButtonEnabled(true);
  }
  return v;
}

相关文章

Activity类方法