Optimize Gradle build
org.gradle.daemon=true
org.gradle.parallel=true
References
https://medium.com/@cesarmcferreira/speeding-up-gradle-builds-619c442113cb#.ihlmwq8zk
org.gradle.daemon=true
org.gradle.parallel=true
References
https://medium.com/@cesarmcferreira/speeding-up-gradle-builds-619c442113cb#.ihlmwq8zk
Keywords
Gradle , Java , plugin
References
https://docs.gradle.org/current/userguide/standard_plugins.html
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
References
http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html
Building in Debug Mode
gradlew.bat assembleDebug
Building in Release Mode
gradlew.bat assembleRelease
References
https://developer.android.com/studio/build/building-cmdline.html
References
http://bryanlor.com/blog/gradle-tutorial-how-install-gradle-windows
https://www.javacodegeeks.com/2013/04/how-to-install-gradle-2.html
getActivity().getFragmentManager().popBackStack();
References :
http://stackoverflow.com/questions/20812922/how-to-close-the-current-fragment-by-using-button-like-the-back-button
Defining a Menu in XML
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/new_game" android:icon="@drawable/ic_new_game" android:title="@string/new_game" android:showAsAction="ifRoom"/> <item android:id="@+id/help" android:icon="@drawable/ic_help" android:title="@string/help" /> </menu>
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/file" android:title="@string/file" > <!-- "file" submenu --> <menu> <item android:id="@+id/create_new" android:title="@string/create_new" /> <item android:id="@+id/open" android:title="@string/open" /> </menu> </item> </menu>
Creating an Options Menu
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.game_menu, menu); return true; }
Handling click events
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.new_game: newGame(); return true; case R.id.help: showHelp(); return true; default: return super.onOptionsItemSelected(item); } }
Changing menu items at runtime
If you want to modify the options menu based on events that occur during the activity lifecycle, you can do so in the onPrepareOptionsMenu() method.
References :
https://developer.android.com/guide/topics/ui/menus.html#options-menu
https://developer.android.com/guide/topics/resources/menu-resource.html
http://stackoverflow.com/questions/15492791/how-do-i-show-overflow-menu-items-to-action-bar-in-android
http://www.techotopia.com/index.php/Creating_and_Managing_Overflow_Menus_on_Android
This is very simple to accomplish
If you want to change it in code, call:
setTitle("My new title"); getActionBar().setIcon(R.drawable.my_icon);
And set the values to whatever you please.
Or, in the Android manifest XML file:
<activity android:name=".MyActivity" android:icon="@drawable/my_icon" android:label="My new title" />
To enable the back button in your app use:
getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
The code should all be placed in your onCreate so that the label/icon changing is transparent to the user, but in reality it can be called anywhere during the activity’s lifecycle.
References :
http://stackoverflow.com/questions/14483393/how-do-i-change-the-android-actionbar-title-and-icon
custom_actionbar.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp" android:background="@drawable/black_pattern" > <TextView android:id="@+id/title_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textAllCaps="true" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#fff" android:textStyle="bold" /> <ImageView android:id="@+id/imageView1" android:layout_width="35dp" android:layout_height="35dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="8dp" android:src="@drawable/ic_launcher" /> <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="8dp" android:background="@null" android:src="@android:drawable/ic_menu_rotate" /> </RelativeLayout>
Activity Class (MainActivity.java)
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar mActionBar = getActionBar(); mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setDisplayShowTitleEnabled(false); LayoutInflater mInflater = LayoutInflater.from(this); View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null); TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text); mTitleTextView.setText("My Own Title"); ImageButton imageButton = (ImageButton) mCustomView .findViewById(R.id.imageButton); imageButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), "Refresh Clicked!", Toast.LENGTH_LONG).show(); } }); mActionBar.setCustomView(mCustomView); mActionBar.setDisplayShowCustomEnabled(true); } }
References :
http://stacktips.com/tutorials/android/actionbar-with-custom-view-example-in-android