Added ActionBar

This commit is contained in:
thibaud 2017-04-20 17:03:03 +02:00
parent 215b8cd2ca
commit 7436afa797
6 changed files with 67 additions and 4 deletions

View File

@ -6,7 +6,6 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

View File

@ -2,6 +2,9 @@ package com.example.diceroller;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@ -13,7 +16,7 @@ import java.util.StringTokenizer;
* Created by thibaud on 20/04/17.
*/
public class DiceActivity extends Activity implements View.OnClickListener {
public class DiceActivity extends AppCompatActivity implements View.OnClickListener {
private TextView textResult;
private int max;
@ -41,4 +44,19 @@ public class DiceActivity extends Activity implements View.OnClickListener {
int result = rand.nextInt(max) + 1;
this.textResult.setText(String.valueOf(result));
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.action_back:
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -3,6 +3,7 @@ package com.example.diceroller;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
@ -33,4 +34,11 @@ public class MainActivity extends AppCompatActivity {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
}

View File

@ -0,0 +1,31 @@
<?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_back"
android:icon="@android:drawable/ic_menu_revert"
android:title="@string/back"
app:showAsAction="always" />
<item
android:id="@+id/action_edit"
android:title="@string/edit"
android:icon="@android:drawable/ic_menu_edit"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/action_add"
android:title="@string/add"
android:icon="@android:drawable/ic_menu_add"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/action_delete"
android:title="@string/delete"
android:icon="@android:drawable/ic_menu_delete"
app:showAsAction="never"
/>
</menu>

View File

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DiceRoller</string>
<string name="_6_sided_dice">Dé à 6 faces</string>
<string name="_20_sided_dice">Dé à 20 faces</string>
<string name="x_sided_dice">faces</string>
<string name="x">X</string>
<string name="roll_dice">Lancer le dé !</string>
<string name="add">Ajouter</string>
<string name="delete">Supprimer</string>
<string name="edit">Éditer</string>
<string name="back">Retour</string>
</resources>

View File

@ -1,8 +1,12 @@
<resources>
<string name="app_name">DiceRoller</string>
<string name="app_name" translatable="false">DiceRoller</string>
<string name="_6_sided_dice">6-sided dice</string>
<string name="_20_sided_dice">20-sided dice</string>
<string name="x_sided_dice">sided dice</string>
<string name="x">X</string>
<string name="roll_dice">Roll dice !</string>
<string name="edit">Edit</string>
<string name="add">Add</string>
<string name="delete">Delete</string>
<string name="back">Back</string>
</resources>