android-actionbar

Add a button to the top right of action bar

元气小坏坏 提交于 2019-12-31 13:13:06
问题 Is there a way I can add a button to the top right of my ActionBar , like where the default settings Button is? I removed the settings Button but I'd like to add a custom Button in it's place. 回答1: You can add a button by editing/create the menu xml file: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_name" android:icon="@drawable/you_resource_here"

Clicking app icon doesn't trigger onOptionsItemSelected()

谁说胖子不能爱 提交于 2019-12-31 11:41:40
问题 I'm currently working on an Android app. I would like to use the app icon in the action bar to navigate to the "home" activity. I read on this page that all that needs to be done is to add an onOptionsItemSelected and look for the id android.R.id.home . This is the code that I have implemented in my activity where I want to press the app icon to return to HomeActivity . @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case android.R.id.home: Intent

Clicking app icon doesn't trigger onOptionsItemSelected()

岁酱吖の 提交于 2019-12-31 11:41:29
问题 I'm currently working on an Android app. I would like to use the app icon in the action bar to navigate to the "home" activity. I read on this page that all that needs to be done is to add an onOptionsItemSelected and look for the id android.R.id.home . This is the code that I have implemented in my activity where I want to press the app icon to return to HomeActivity . @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case android.R.id.home: Intent

Customizing android.widget.SearchView

走远了吗. 提交于 2019-12-31 10:54:33
问题 Is it possible to customize layout of android.widget.SearchView (I'm using it in actionBar)? I want to change icon and TextField background. 回答1: I've found the only one way to do that- to use reflections. SearchView mSearchView = (SearchView)menu.findItem(R.id.search).getActionView(); try { Field searchField = SearchView.class.getDeclaredField("mSearchButton"); searchField.setAccessible(true); ImageView searchBtn = (ImageView)searchField.get(mSearchView); searchBtn.setImageResource(R

Customizing android.widget.SearchView

我的梦境 提交于 2019-12-31 10:54:07
问题 Is it possible to customize layout of android.widget.SearchView (I'm using it in actionBar)? I want to change icon and TextField background. 回答1: I've found the only one way to do that- to use reflections. SearchView mSearchView = (SearchView)menu.findItem(R.id.search).getActionView(); try { Field searchField = SearchView.class.getDeclaredField("mSearchButton"); searchField.setAccessible(true); ImageView searchBtn = (ImageView)searchField.get(mSearchView); searchBtn.setImageResource(R

Put switch inside action bar on Android

久未见 提交于 2019-12-31 10:33:25
问题 I'm working on a project where I am currently trying to put a switch inside the applications action bar (as in the wi-fi settings : http://tinypic.com/r/2l8vt35/6 ) How can this be done? 回答1: Add android:actionLayout to your <item> in your menu XML resource, pointing to a layout XML resource that has your Switch . Then, use getActionView() on the MenuItem to register listeners on changes in the switch. Note that Switch only works on API Level 14 and higher. 来源: https://stackoverflow.com

Put switch inside action bar on Android

こ雲淡風輕ζ 提交于 2019-12-31 10:33:05
问题 I'm working on a project where I am currently trying to put a switch inside the applications action bar (as in the wi-fi settings : http://tinypic.com/r/2l8vt35/6 ) How can this be done? 回答1: Add android:actionLayout to your <item> in your menu XML resource, pointing to a layout XML resource that has your Switch . Then, use getActionView() on the MenuItem to register listeners on changes in the switch. Note that Switch only works on API Level 14 and higher. 来源: https://stackoverflow.com

Add a different color for each action bar tabs separately

拥有回忆 提交于 2019-12-31 05:32:06
问题 I need to add a different color for every tabs. For Eg: like this below image MainActivity.java: // Add New Tab actionBar.addTab(actionBar.newTab().setText("Home") .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("News") .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Latest") .setTabListener(tabListener)); Home.java: public class Home extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,

Add a different color for each action bar tabs separately

孤人 提交于 2019-12-31 05:32:01
问题 I need to add a different color for every tabs. For Eg: like this below image MainActivity.java: // Add New Tab actionBar.addTab(actionBar.newTab().setText("Home") .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("News") .setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Latest") .setTabListener(tabListener)); Home.java: public class Home extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,

changing ActionBar's height in orientation mode

旧城冷巷雨未停 提交于 2019-12-30 12:04:11
问题 I have been using actionbar(android native) for a few days(jellybean 4.2). I tried to change the actionbar's height by adding such line in style.xml: 100dip it works fine in landscapemode, but do not work in orientation mode. in orientation mode, its height was not changed. 回答1: You just have to create dimensions for the height of the ActionBar in portrait and landscape mode: values/dimens.xml : <resources> <!-- dimension for the portrait ActionBar --> <dimen name="ab_height">100dp</dimen> <