Implement a bar with some buttons in android - java

I'm having some difficulties to reach a way of implementing an layout that i want for a android project. I have to make a layout like this:
This bar is at the top of the android screen over a map of google and each icon are a button. The map is already in the layout at this time.
Whats the simple way of doing this with android layout?
After that and not so important at this time, after click each button i have to open a rectangle with some options to fill (text boxs and dropdown lists) but i know that i can do this with a alert dialog. Is this the best way for doing this part?
Regards for the help

you can use third party libraries for this. ActionBarSherlock is the library which you can use.
Here's a link Click here to download
and for tutorial follow this link.
thanks

You can use an Action Bar, and overlay it on top of the map.
To enable overlay mode of the action bar, you have to create a custom theme and modify some values:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
More information on this in this android documentation

Related

Android Status bar and Navigation issues

Recently I used this java code in Main_Activity:
(getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS))
for status Bar Transparent purpose. All went well, but my Android Navigation Bar also went to transparent policy.
Now I need only transparent my Status Bar, but not the Navigation Bar.
You have two options to do, first, one which I recommend for you would be using an external library for status-bar styling like StatusBarUtil library, which enables you to fulfill your requirement in just one line:
StatusBarUtil.setTransparent(Activity activity) // yo be placed in every activity you want the status bar to be transparent in
And this library doesn't affect the navigation bar.
Just make sure first to implement the library in your app level Gradle:
implementation'com.jaeger.statusbarutil:library:1.5.1'
Second option, is to go for layout customization, as mentioned in this tutorial, you can add the following to your style.xml:
<style name="AppTheme.TransparentTheme">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
And apply this style to the Activity in the manifest:
<activity
android:name=".HomeActivity"
android:theme="#style/AppTheme.TransparentTheme">
</activity>
As described in the tutorial:
I have set android:windowDrawsSystemBarBackgrounds to true.
This is a flag whose description is given below:
Flag indicating whether this Window is responsible for drawing the
background for the system bars. If true and the window is not
floating, the system bars are drawn with a transparent background and
the corresponding areas in this window are filled with the colors
specified in {#link android.R.attr#statusBarColor} and {#link
android.R.attr#navigationBarColor}. Corresponds to {#link
android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}.
Don't forget to add the attribute android:fitsSystemWindows="true" to the top root of your activity layout.

How can i change android actionbar picture

i am new on android and i am using android studio to develop. i want to change actionbar top right corner button image to another one but after compile to my android device the button still remain the ... but my customize image. please help!! below is my code. my public class is extend activity.
menu.xml
android:id="#+id/action_share"
android:orderInCategory="100"
android:title="Share"
android:icon="#drawable/ic_search_black"
app:showAsAction="ifRoom"
Vic3ai, That icon all the way to the right is the Action Overflow and it will always show a drop down list of action buttons that don't fit on the actionbar (either because there isn't room or because we decided to put some in the overflow on purpose).
This might give you a better idea of what the overflow is and is used for, as well as a general overview of the actionbar - http://developer.android.com/design/patterns/actionbar.html.
It sounds like what you actually want is to add an action button to your action bar. You can do that like so:
First add a new item in your menu.xml for which ever activity you want it to appear in:
<item
android:id="#+id/camera_button"
android:title="#string/camera"
android:icon="#drawable/camera_icon"
android:orderInCategory="100"
android:showAsAction="always"
/>
Here the important thing is android:showAsAction="always". This is what makes it appear as an action button on the action bar. You could also use value 'ifRoom', which does what it says on the tin: If there's room on the actionbar the button will display, otherwise it goes into the action overflow.
Now that we have the actionbutton in existence we go to our actvity.java and respond to the button:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.camera_button:
//your code here, eg:
openCamera();
return true;
// if you have other buttons, more cases would go here
}
return super.onOptionsItemSelected(item);
}
So far this should give you an Action Button on the actionbar that will run whatever could you define in your activity.java but the action overflow will still be there. The easiest way to remove it is to go back to your menu.xml and remove/change any items that would appear in the overflow.
android:showAsAction="never"
will automatically put action in to the overflow
If you have a lot of action buttons and any of them have android:showAsAction="ifRoom", you might find an overflow button on the far right again
NOTE, use app:showAsAction="always" instead of android namespace if you're using appCompat compatibility.
Hope this helps!
To change the Action Overflow Icon - default is three vertical dots - you have to add an actionOverflowButtonStyle item to your main theme declaration AND then define it in styles.xml:
<resources>
<!-- base application theme -->
<style
name="AppTheme" parent="#android:style/Theme.Holo">
<!-- include overflow style in theme -->
<item name="android:actionOverflowButtonStyle">#style/OverFlowIcon</item>
</style>
<!-- styles -->
<style
name="OverFlowIcon"
parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_search_black</item>
</style>
</resources>
Of course if you're using AppCompat themes don't forget to use atributes without the android namespace or it wont work - ie
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
instead of what you see above.
Also don't forget to include your theme in application tag of AndroidManifest.xml if you change make a custom theme:
<application
android:name="com.example.android.MainApp"
android:theme="#style/AppTheme">
</application>

Overlay image on Action Bar

How do I overlay image over an Action Bar and status bar? Here is what I want it to look like -
I read this but it gives different results than what I want. The Action Bar still has some opacity and the status bar has no effect at all.
Is there any way to do this?
Add these two lines of code to your styles-v21.xml file:
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionModeOverlay">true</item>
Edit:
You want it in the v21 file because Android versions below 5.0 don't support this.
Also...for Material Design, you should be using a ToolBar not an Action Bar. Here's how to change the color of a Toolbar.
toolbar.getBackground().setAlpha(0);
Check this answer.
This one worked perfectly in my project.
This library is also great to explore:
https://github.com/ManuelPeinado/FadingActionBar

Creating bodyless activity

Currently I am trying to make an activity that can be moved on the screen , in other words this activity can float on the screen. I know I am missing something that should be added to achieve this functionality.
What should I do to achieve floating activity which can be moved around anywhere on the screen?
If you're looking to do something similar to the Facebook chat circles (where you have a view on top of other apps) then take a look here: http://www.cloudinfy.com/2013/06/android-chat-head-view-like-in-facebook.html
Basically you need to start a service and add a view to the window manager.
If you're looking to simply create an activity to look like a dialog then have a look here: Android Activity as a dialog
This is very similar to a normal activity but the theme is set to Theme.Dialog
There's a good solution here: http://cases.azoft.com/android-tutorial-floating-activity/
They just add an attribute to the theme of a tablet Activity:
<item name="android:windowIsTranslucent">true</item>
If any problems on KitKat devices, add some lines to the theme:
<item name="android:windowIsFloating">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:backgroundDimEnabled">true</item>

Number of tabs in ActionBar

Android's ActionBar has a mode NAVIGATION_MODE_TABS. Using ActionBarSherlock 3.5.1 I have set this ActionBar and addded 5 tabs. On 2.x devices I see all tabs without horizontal scrolling. On 4.0.x I see only 3 tabs with scrollable layout. NAVIGATION_MODE_TABS of ActionBar can contain max 3 tabs in ICS? If yes, could I hack this somehow? I know, i could create custom TabHost, but it would be quite time consuming to implement it with ViewPager between tab views.
You don't need to hack anything. The ActionBar tabs have specific layout parameters that you can change pretty easily through a custom style. Google uses their own style to set them in the first place. You should take a look at this on creating custom styles. http://android-developers.blogspot.com/2011/04/customizing-action-bar.html Since you want them to look like they way Jake Wharton has them set in ActionBarSherlock, then you could make things even easier for yourself and just rip his styles out.
I had the same problem with action bar sherlock, and this post helped me.
How to manage the width of ActionBar navigation tabs?
Important part is
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>

Categories