Java Code Examples for android.support.v7.app.ActionBar#setCustomView()
The following examples show how to use
android.support.v7.app.ActionBar#setCustomView() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseActivity.java From SpecialAlarmClock with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.middle_title_actionbar); try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } }
Example 2
Source File: NetMediaActivty.java From KSYMediaPlayer_Android with Apache License 2.0 | 6 votes |
public void setActionBarLayout(int layoutId, Context mContext) { ActionBar actionBar = getSupportActionBar(); if (null != actionBar) { actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(layoutId, new LinearLayout(mContext), false); ActionBar.LayoutParams layout = new ActionBar.LayoutParams( ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT); actionBar.setCustomView(v, layout); netHistory = (Button) findViewById(R.id.net_history); netScan = (Button) findViewById(R.id.net_scan); netSetting = (Button) findViewById(R.id.net_setting); netScan.setOnClickListener(this); netHistory.setOnClickListener(this); netSetting.setOnClickListener(this); }else{ Toast.makeText(NetMediaActivty.this, "ActionBar不存在", Toast.LENGTH_SHORT).show(); } }
Example 3
Source File: MainActivity.java From KSYMediaPlayer_Android with Apache License 2.0 | 6 votes |
public void setActionBarLayout(int layoutId, Context mContext) { ActionBar actionBar = getSupportActionBar(); if (null != actionBar) { actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(layoutId, new LinearLayout(mContext), false); ActionBar.LayoutParams layout = new ActionBar.LayoutParams( ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT); actionBar.setCustomView(v, layout); media_net = (Button)findViewById(R.id.media_network); media_history = (Button)findViewById(R.id.media_history); media_setting = (Button)findViewById(R.id.media_setting); media_net.setOnClickListener(this); media_setting.setOnClickListener(this); media_history.setOnClickListener(this); }else{ Toast.makeText(MainActivity.this, "ActionBar不存在", Toast.LENGTH_SHORT).show(); } }
Example 4
Source File: ActionBarDisplayOptions.java From V.FlyoutTest with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.action_bar_display_options); findViewById(R.id.toggle_home_as_up).setOnClickListener(this); findViewById(R.id.toggle_show_home).setOnClickListener(this); findViewById(R.id.toggle_use_logo).setOnClickListener(this); findViewById(R.id.toggle_show_title).setOnClickListener(this); findViewById(R.id.toggle_show_custom).setOnClickListener(this); findViewById(R.id.toggle_navigation).setOnClickListener(this); findViewById(R.id.cycle_custom_gravity).setOnClickListener(this); findViewById(R.id.toggle_visibility).setOnClickListener(this); // Configure several action bar elements that will be toggled by display options. mCustomView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null); mCustomViewLayoutParams = new ActionBar.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final ActionBar bar = getSupportActionBar(); bar.setCustomView(mCustomView, mCustomViewLayoutParams); bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this)); bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this)); bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this)); }
Example 5
Source File: MainActivity.java From QueryHighlighter with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAdapter = new CheesesAdapter(); final ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(mAdapter); final ActionBar actionBar = getSupportActionBar(); actionBar.setCustomView(R.layout.search_view); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); final EditText editText = (EditText) actionBar.getCustomView(); editText.addTextChangedListener(mTextWatcher); editText.requestFocus(); }
Example 6
Source File: ChatActivity.java From Yahala-Messenger with MIT License | 6 votes |
@Override public void applySelfActionBar() { if (parentActivity == null) { return; } try { ActionBar actionBar = parentActivity.getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowCustomEnabled(false); actionBar.setCustomView(null); updateSubtitle(); ((LaunchActivity) parentActivity).fixBackButton(); } catch (Exception e) { e.printStackTrace(); } }
Example 7
Source File: AnagramFragment.java From Anagram-Solver with MIT License | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ActionBar actionbar = ((MainActivity) getActivity()).getSupportActionBar(); actionbar.show(); actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionbar.setCustomView(R.layout.actionbar_view); }
Example 8
Source File: CalendarActivityFragment.java From FlexibleCalendar with MIT License | 5 votes |
public void setupToolBar(View mainView) { Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar); ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); ActionBar bar = ((AppCompatActivity) getActivity()).getSupportActionBar(); bar.setDisplayHomeAsUpEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setDisplayShowCustomEnabled(true); someTextView = new TextView(getActivity()); someTextView.setTextColor(getActivity().getResources().getColor(R.color.title_text_color_activity_1)); someTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (calendarView.isShown()) { calendarView.collapse(); } else { calendarView.expand(); } } }); bar.setCustomView(someTextView); bar.setBackgroundDrawable(new ColorDrawable(getActivity().getResources() .getColor(R.color.action_bar_color_activity_1))); //back button color // final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); // upArrow.setColorFilter(getResources().getColor(R.color.title_text_color_activity_1), PorterDuff.Mode.SRC_ATOP); // bar.setHomeAsUpIndicator(upArrow); }
Example 9
Source File: RecyclerViewFragment.java From kernel_adiutor with Apache License 2.0 | 5 votes |
public void setProgressBar(ProgressBar progressBar) { progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000, getResources().getColor(android.R.color.white))); ActionBar actionBar; if ((actionBar = getActionBar()) != null) { actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END)); } }
Example 10
Source File: ClanUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public static void initCustomActionBar(AppCompatActivity activity) { ActionBar actionBar = activity.getSupportActionBar(); actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(R.layout.pure_android_action_bar); }
Example 11
Source File: BaseActivity.java From SimpleAdapterDemo with Apache License 2.0 | 5 votes |
@Override protected void initActionBar(ActionBar actionBar) { if (actionBar == null) return; int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12); FrameLayout customView = new FrameLayout(this); // customView.setPadding(padding, 0, padding, 0); ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this)); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customView, barParams); //添加标题 tvTitle = new TextView(this); tvTitle.setTextColor(Color.WHITE); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvTitle.setGravity(Gravity.CENTER); customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); //添加返回按钮 ivBack = new ImageView(this); ivBack.setPadding(padding / 2, 0, padding / 2, 0); ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp); ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this)); customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); //添加menu菜单 actionMenuView = new ActionMenuView(this); FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL; customView.addView(actionMenuView, menuParams); }
Example 12
Source File: BaseActivity.java From WheelViewDemo with Apache License 2.0 | 5 votes |
@Override protected void initActionBar(ActionBar actionBar) { if (actionBar == null) return; int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12); FrameLayout customView = new FrameLayout(this); // customView.setPadding(padding, 0, padding, 0); ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this)); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customView, barParams); //添加标题 tvTitle = new TextView(this); tvTitle.setTextColor(Color.WHITE); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvTitle.setGravity(Gravity.CENTER); customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); //添加返回按钮 ivBack = new ImageView(this); ivBack.setPadding(padding / 2, 0, padding / 2, 0); ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp); ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this)); customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); //添加menu菜单 actionMenuView = new ActionMenuView(this); FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL; customView.addView(actionMenuView, menuParams); }
Example 13
Source File: BaseActivity.java From CameraMaskDemo with Apache License 2.0 | 5 votes |
@Override protected void initActionBar(ActionBar actionBar) { if (actionBar == null) return; int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12); FrameLayout customView = new FrameLayout(this); // customView.setPadding(padding, 0, padding, 0); ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this)); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customView, barParams); //添加标题 tvTitle = new TextView(this); tvTitle.setTextColor(Color.WHITE); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvTitle.setGravity(Gravity.CENTER); customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); //添加返回按钮 ivBack = new ImageView(this); ivBack.setPadding(padding / 2, 0, padding / 2, 0); ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp); ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this)); customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); //添加menu菜单 actionMenuView = new ActionMenuView(this); FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL; customView.addView(actionMenuView, menuParams); }
Example 14
Source File: SettingsActivity.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { ((IslamicLibraryApplication) getApplication()).refreshLocale(this, false); super.onCreate(savedInstanceState); // Enable if you use AppCompat 24.1.x. // Fixes.updateLayoutInflaterFactory(getLayoutInflater()); setContentView(R.layout.activity_settings); mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy .ReplaceFragment(this, R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out); if (savedInstanceState == null) { mSettingsFragment = SettingsFragment.newInstance(null); getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit(); } else { mSettingsFragment = (SettingsFragment) getSupportFragmentManager().findFragmentByTag("Settings"); } getSupportFragmentManager().addOnBackStackChangedListener(this); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); ActionBar ab = getSupportActionBar(); // Cross-fading title setup. mTitle = getTitle(); mTitleSwitcher = new TextSwitcher(mToolbar.getContext()); mTitleSwitcher.setFactory(() -> { TextView tv = new AppCompatTextView(mToolbar.getContext()); TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title); return tv; }); mTitleSwitcher.setCurrentText(mTitle); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); ab.setCustomView(mTitleSwitcher); ab.setDisplayShowCustomEnabled(true); ab.setDisplayShowTitleEnabled(false); } // Add to hierarchy before accessing layout params. int margin = Util.dpToPxOffset(this, 16); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams(); lp.leftMargin = margin; lp.rightMargin = margin; mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in); mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out); }
Example 15
Source File: EmptyFragmentActivity.java From WheelViewDemo with Apache License 2.0 | 4 votes |
@Override public void initActionBar(ActionBar actionBar) { if (actionBar == null) return; //You can initialize custom action bar here. int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12); FrameLayout customView = new FrameLayout(this); // customView.setPadding(padding, 0, padding, 0); ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this)); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customView, barParams); //添加标题 TextView tvTitle = new TextView(this); tvTitle.setTextColor(Color.WHITE); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvTitle.setGravity(Gravity.CENTER); tvTitle.setText(getClass().getSimpleName().replace("Activity", "")); customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); //添加返回按钮 ImageView ivBack = new ImageView(this); ivBack.setPadding(padding / 2, 0, padding / 2, 0); ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp); ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this)); customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); //添加menu菜单 ActionMenuView actionMenuView = new ActionMenuView(this); FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL; customView.addView(actionMenuView, menuParams); String title = getIntent().getStringExtra(EXTRA_TITLE); tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title); }
Example 16
Source File: UIManagerAppCompat.java From document-viewer with GNU General Public License v3.0 | 4 votes |
public static void setProgressSpinnerVisible(AppCompatActivity activity, boolean visible) { ActionBar bar = activity.getSupportActionBar(); if (bar.getCustomView() == null) { ProgressBar spinner = new ProgressBar(activity); spinner.setIndeterminate(true); bar.setCustomView(spinner); } bar.setDisplayShowCustomEnabled(visible); }
Example 17
Source File: ActionBarDisplayOptions.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void onClick(View v) { final ActionBar bar = getSupportActionBar(); int flags = 0; switch (v.getId()) { case R.id.toggle_home_as_up: flags = ActionBar.DISPLAY_HOME_AS_UP; break; case R.id.toggle_show_home: flags = ActionBar.DISPLAY_SHOW_HOME; break; case R.id.toggle_use_logo: flags = ActionBar.DISPLAY_USE_LOGO; break; case R.id.toggle_show_title: flags = ActionBar.DISPLAY_SHOW_TITLE; break; case R.id.toggle_show_custom: flags = ActionBar.DISPLAY_SHOW_CUSTOM; break; case R.id.toggle_navigation: bar.setNavigationMode( bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD ? ActionBar.NAVIGATION_MODE_TABS : ActionBar.NAVIGATION_MODE_STANDARD); return; case R.id.cycle_custom_gravity: { ActionBar.LayoutParams lp = mCustomViewLayoutParams; int newGravity = 0; switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: newGravity = Gravity.CENTER_HORIZONTAL; break; case Gravity.CENTER_HORIZONTAL: newGravity = Gravity.RIGHT; break; case Gravity.RIGHT: newGravity = Gravity.LEFT; break; } lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity; bar.setCustomView(mCustomView, lp); return; } case R.id.toggle_visibility: if (bar.isShowing()) { bar.hide(); } else { bar.show(); } return; } int change = bar.getDisplayOptions() ^ flags; bar.setDisplayOptions(change, flags); }
Example 18
Source File: ActivitySettings.java From fingen with Apache License 2.0 | 4 votes |
@SuppressLint("PrivateResource") @Override protected void onCreate(Bundle savedInstanceState) { switch (Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "0"))) { case ActivityMain.THEME_LIGHT : setTheme(R.style.AppThemeLight); break; case ActivityMain.THEME_DARK : setTheme(R.style.AppThemeDark); break; default: setTheme(R.style.AppThemeLight); break; } super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy.ReplaceFragment(this, R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out); if (savedInstanceState == null) { mSettingsFragment = FragmentSettings.newInstance(null); getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit(); } else { mSettingsFragment = (FragmentSettings) getSupportFragmentManager().findFragmentByTag("Settings"); } getSupportFragmentManager().addOnBackStackChangedListener(this); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); ActionBar ab = getSupportActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); } // Cross-fading title setup. mTitle = getTitle(); mTitleSwitcher = new TextSwitcher(mToolbar.getContext()); mTitleSwitcher.setFactory(new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView tv = new AppCompatTextView(mToolbar.getContext()); TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title); return tv; } }); mTitleSwitcher.setCurrentText(mTitle); if (ab != null) { ab.setCustomView(mTitleSwitcher); ab.setDisplayShowCustomEnabled(true); ab.setDisplayShowTitleEnabled(false); } // Add to hierarchy before accessing layout params. // int margin = Util.dpToPxOffset(this, 16); // ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams(); // lp.leftMargin = margin; // lp.rightMargin = margin; mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in); mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out); android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); }
Example 19
Source File: ChatToolbarFragment.java From actor-platform with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onConfigureActionBar(ActionBar actionBar) { super.onConfigureActionBar(actionBar); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); // Loading Toolbar header views ActorStyle style = ActorSDK.sharedActor().style; barView = LayoutInflater.from(getActivity()).inflate(R.layout.bar_conversation, null); actionBar.setCustomView(barView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)); Toolbar parent = (Toolbar) barView.getParent(); parent.setContentInsetsAbsolute(0, 0); barView.findViewById(R.id.home).setOnClickListener(v -> { Activity activity = getActivity(); if (activity != null) { activity.onBackPressed(); } }); counter = (TextView) barView.findViewById(R.id.counter); counter.setTextColor(style.getDialogsCounterTextColor()); counter.setBackgroundResource(R.drawable.ic_counter_circle); counter.getBackground().setColorFilter(style.getDialogsCounterBackgroundColor(), PorterDuff.Mode.MULTIPLY); barTitle = (TextView) barView.findViewById(R.id.title); barSubtitleContainer = barView.findViewById(R.id.subtitleContainer); barTypingIcon = (ImageView) barView.findViewById(R.id.typingImage); barTypingIcon.setImageDrawable(new TypingDrawable()); barTyping = (TextView) barView.findViewById(R.id.typing); barSubtitle = (TextView) barView.findViewById(R.id.subtitle); barTypingContainer = barView.findViewById(R.id.typingContainer); barTypingContainer.setVisibility(View.INVISIBLE); barAvatar = (AvatarView) barView.findViewById(R.id.avatarPreview); barAvatar.init(Screen.dp(32), 18); barView.findViewById(R.id.titleContainer).setOnClickListener(v -> { if (peer.getPeerType() == PeerType.PRIVATE) { ActorSDKLauncher.startProfileActivity(getActivity(), peer.getPeerId()); } else if (peer.getPeerType() == PeerType.GROUP) { ActorSDK.sharedActor().startGroupInfoActivity(getActivity(), peer.getPeerId()); } else { // Nothing to do } }); }
Example 20
Source File: EmptyFragmentActivity.java From SimpleAdapterDemo with Apache License 2.0 | 4 votes |
@Override public void initActionBar(ActionBar actionBar) { if (actionBar == null) return; //You can initialize custom action bar here. int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12); FrameLayout customView = new FrameLayout(this); // customView.setPadding(padding, 0, padding, 0); ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this)); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customView, barParams); //添加标题 TextView tvTitle = new TextView(this); tvTitle.setTextColor(Color.WHITE); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvTitle.setGravity(Gravity.CENTER); tvTitle.setText(getClass().getSimpleName().replace("Activity", "")); customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); //添加返回按钮 ImageView ivBack = new ImageView(this); ivBack.setPadding(padding / 2, 0, padding / 2, 0); ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp); ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this)); customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); //添加menu菜单 ActionMenuView actionMenuView = new ActionMenuView(this); FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL; customView.addView(actionMenuView, menuParams); String title = getIntent().getStringExtra(EXTRA_TITLE); tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title); }