Advertisement
onzulin

proyecto actionbar android studio

Aug 1st, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. //Todos los comentarios estan en el formato de Java o // o /* comentario multi linea */
  2. MainActivity.java
  3. package com.techcomputerworld.tcw.testactionbar;
  4.  
  5. //import android.app.ActionBar;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.support.v7.app.ActionBar;
  8. import android.os.Bundle;
  9. import android.support.v7.widget.Toolbar;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13.     @Override
  14.     protected void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.  
  18.         Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  19.         setSupportActionBar(myToolbar);
  20.         ActionBar ab = getSupportActionBar();
  21.         ab.setDisplayHomeAsUpEnabled(true);
  22.  
  23.     }
  24. }
  25. // Los XML los pongo aqui
  26. /*
  27.  * Activity_main.xml
  28.  */
  29. <?xml version="1.0" encoding="utf-8"?>
  30. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  31.     xmlns:app="http://schemas.android.com/apk/res-auto"
  32.     xmlns:tools="http://schemas.android.com/tools"
  33.     android:layout_width="match_parent"
  34.     android:layout_height="match_parent"
  35.     tools:context="com.techcomputerworld.tcw.testactionbar.MainActivity">
  36.  
  37.     <android.support.v7.widget.Toolbar
  38.         android:id="@+id/my_toolbar"
  39.         android:layout_width="match_parent"
  40.         android:layout_height="?attr/actionBarSize"
  41.         android:background="?attr/colorPrimary"
  42.         android:elevation="4dp"
  43.         android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
  44.         app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
  45.  
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World!"
  50.         app:layout_constraintBottom_toBottomOf="parent"
  51.         app:layout_constraintLeft_toLeftOf="parent"
  52.         app:layout_constraintRight_toRightOf="parent"
  53.         app:layout_constraintTop_toTopOf="parent" />
  54.  
  55. </android.support.constraint.ConstraintLayout>
  56.  
  57. /*
  58.  *  menu.xml
  59.  */
  60. <?xml version="1.0" encoding="utf-8"?>
  61. <menu xmlns:android="http://schemas.android.com/apk/res/android"
  62.     xmlns:app="http://schemas.android.com/apk/res-auto">
  63.     <item android:id="@+id/action_setting"
  64.         android:title="@string/action_setting"
  65.         android:orderInCategory="100"
  66.         app:showAsAction="never"/>
  67. </menu>
  68. /*
  69.  * build.gradle
  70. */
  71. apply plugin: 'com.android.application'
  72.  
  73. android {
  74.     compileSdkVersion 25
  75.     buildToolsVersion "25.0.2"
  76.     defaultConfig {
  77.         applicationId "com.techcomputerworld.tcw.testactionbar"
  78.         minSdkVersion 19
  79.         targetSdkVersion 25
  80.         versionCode 1
  81.         versionName "1.0"
  82.         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  83.     }
  84.     buildTypes {
  85.         release {
  86.             minifyEnabled false
  87.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  88.         }
  89.     }
  90. }
  91.  
  92. dependencies {
  93.     compile fileTree(dir: 'libs', include: ['*.jar'])
  94.     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  95.         exclude group: 'com.android.support', module: 'support-annotations'
  96.     })
  97.     compile 'com.android.support:appcompat-v7:25.1.1'
  98.     compile 'com.android.support.constraint:constraint-layout:1.0.2'
  99.     testCompile 'junit:junit:4.12'
  100. }
  101. /*
  102.  * strings.xml  
  103.  */
  104. <resources>
  105.     <string name="app_name">TestActionBar</string>
  106.     <string name="action_setting">Setting</string>
  107. </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement