Pages

Showing posts with label actionbar. Show all posts
Showing posts with label actionbar. Show all posts

Friday, February 26, 2016

Find debug keystore and SHA1 in Android Studio


This video show how to find debug.keystore and SHA1 in Android Studio:


Read More..

Thursday, February 11, 2016

Replace ActionBar with android support v7 widget Toolbar

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activitys opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setSupportActionBar() method.

This example show how to replace ActionBar with android.support.v7.widget.Toolbar.


- Create a new project with Minimum SDK of API 16, select template of Empty Activity.

- Edit res/values/styles.xml to use style of "Theme.AppCompat.Light.NoActionBar".
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

- Add <android.support.v7.widget.Toolbar> to /res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

android_layout_width="match_parent"
android_layout_height="match_parent"
android_paddingBottom="@dimen/activity_vertical_margin"
android_paddingLeft="@dimen/activity_horizontal_margin"
android_paddingRight="@dimen/activity_horizontal_margin"
android_paddingTop="@dimen/activity_vertical_margin"
tools_context="com.blogspot.android_er.androidtoolbar.MainActivity">

<android.support.v7.widget.Toolbar
android_id="@+id/toolbar"
android_layout_width="match_parent"
android_layout_height="56dp"
android_background="#FFA000"/>

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_text="Hello World!" />
</RelativeLayout>


- Edit MainActivity.java to call setSupportActionBar(toolbar) method.
package com.blogspot.android_er.androidtoolbar;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

}
}


- To make the Toolbar fill the width of the layout, edit /res/values/dimens.xml to set both "activity_horizontal_margin" and "activity_vertical_margin" to 0dp.
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

</resources>


This video show how-to in Android Studio, and how it shown on Android Emulator of API 16 and 23.


More:
- Set title, subtitle and logo of Toolbar
- Add OptionsMenu to Toolbar
- Set image on Toolbar
- Implement checkable items in OptionsMenu of Toolbar

Read More..