I tried the following code from the Android documentation, to display the 'up button':
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
... }
According to the documentation the 'up botton' should look like this.
However, on my phone with Android 4.2 it looks more like this.
The arrow is separated from the logo and takes too much place. How can I get the small arrow in combination with the logo?
you can use toolbar and use setNavigationIcon() method to change the navigation icon
toolbar.setNavigationIcon(R.drawable.SomeIcon);
Related
Just like the title says I'm trying to get rid of this bar and I could find no reference to it anywhere in my xml or code. I was looking around on this website also and could not find a suggestion that worked. I mean the blue area that says listview on it. Thanks!
https://i.stack.imgur.com/YWUWG.jpg
You can take away it in your Activity like this
onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// use this before you create a view
ActionBar actionBar = getSupportedActionBar();
if(actionBar != null){
actionBar.hide();
}
setContentView(R.layout.some_layout);
...
}
Hey guys I'm having a small issue I cant for the life of me figure out what I did wrong to not allow myself to change the background color in my app. See image for example at the Top where it says AppStack I want to change the background color of that instead of it being white. Is there something I am missing any help would be greatly appreciated thank you.!
I think you mean to the AppBar color.
You can do it with
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.mycolor));
Add value in colors:
<color name="mycolor">#FFFFFF</color>
The answer is from here:
Change action bar color in android
If you want to do in XML
Try this tutorial from google
If you want to set it up in code:
public class MainActivity extends AppCompact {
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.BLUE)); // set your desired color
...
}
...
}
The activity theme is Theme.AppCompat.Light.DialogWhenLarge. I can not get the activity to resize when keyboard is up. Configuring android:windowSoftInputMode="adjustResize" or getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
has no effect, all I'm getting is adjustPan behaviour. However, I can confirm that adjustNothing works. Any ideas how to make an activity with DialogWhenLarge theme to resize with keyboard?
Result with adjustResize:
Result with adjustNothing:
I've found a workaround, but would still like to hear if anyone had a similar problem.
Workaround:
Replaced Activity's theme DialogWhenLarge with Theme.AppCompat.Light.Dialog. This allows the adjustResize to behave as expected with ActionBarActivity
Added toolbar.xml layout as android.support.v7.widget.Toolbar
Assigned the toolbar as action bar in my Activity
Set activity's height for 10' tablets layout-sw720dp to 500dp for better presentation
Configure toolbar as action bar:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout...);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
}
More on toolbar at android developer blog and stackoverflow
with below code , i make a Transparent Actionbar for my FragmentActivity & all fragments:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#64000000")));
setContentView(R.layout.main_slidemenu);
.
.
.
}
But i have a problem with this , i need to SlideMenu just open under actionbar , but it open i all of layout.
You are probably looking for the ActionBar overlay mode.
Enable it for a single Activity by calling requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); before setContentView(). Or in a theme by setting android:windowActionBarOverlay to true.
if you've used SlidingMenu library you could use :
setSlidingActionBarEnabled(false);
but according to the link you've provided you have used NavigationDrawer , with NavigationDrawer i think you could use layout_marginTop for your NavigationDrawer in it's layout xml and for better achievement , get your ActionBar height dynamically then set margin to that.
and also try removing line below:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
i've used NavigationDrawer before without setting Layout_marginTop and Window.FEATURE_ACTION_BAR_OVERLAY and its below my ActionBar.
I want to remove the left arrow from the action bar and only icon and title needed.
My code:
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.dashboardtitle);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
But this doesn't remove the left arrow . Any help!!
According to specification android specification:
To enable the icon for up navigation (which displays the "up" indicator next to the icon), call setDisplayHomeAsUpEnabled(true) on your ActionBar:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
...
}
So you should set actionBar.setDisplayHomeAsUpEnabled(false);
UPDATE:
I test next code with ActionBar sherlock and it's work. There is no back arrow:
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.about_event_location);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
You need to add this to your actionBar theme. You can replace arrow image with your own image which can be transparent
<item name="android:homeAsUpIndicator">#drawable/action_arrow</item>
getActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
Where action_arrow is a 25x10px transparent png.
Same code for sherlock would be:
getSupportActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
#vivek: works great. I do not recommend to use #android:color/transparent as Tim Cooper said, because the Title is aligned to the left. So a empty image is better
In AndroidManifest.xml
remove the below code, which will remove back button from your ActionBar
android:parentActivityName=".Main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main.MainActivity" />
Just keep it like below:
<activity
android:name=".YourActivity"
android:label="#string/your_activity_label">
</activity>