Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Este codigo es de la actividad principal donde pongo la Toolbar
- <!-- /res/layout/activity_main.xml -->
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.techcomputerworld.tcw.test_menu.MainActivity">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:elevation="4dp"
- android:theme="?attr/actionBarTheme"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
- />
- </RelativeLayout>
- /*
- * otra layout que define el menu que solo he puesto uno
- */
- <!-- /res/menu/actionmenu.xml -->
- <?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">
- <!-- "Mark Favorite", should appear as action button if possible -->
- <item
- android:id="@+id/action_favorite"
- android:icon="@drawable/ic_favorite_black"
- android:title="@string/action_favorite"
- app:showAsAction="ifRoom"/>
- <!-- Settings, should always be in the overflow -->
- <item android:id="@+id/action_settings"
- android:title="@string/action_settings"
- app:showAsAction="never"/>
- </menu>
- /*
- * Aqui ya pongo codigo en Java para que lo veais y tambien pondre el manifiesto de la aplicacion que es importante añadir la linea que hay que añadir
- mainactivity.java
- */
- package com.techcomputerworld.tcw.test_menu;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.widget.Toolbar;
- import android.view.MenuItem;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar maintoolbar = (Toolbar)findViewById(R.id.toolbar);
- setSupportActionBar(maintoolbar);
- //obtener el soporte correspondiente a la toolbar
- ActionBar ab = getSupportActionBar();
- //Enable the Up Button
- ab.setDisplayHomeAsUpEnabled(true);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_settings:
- // User chose the "Settings" item, show the app settings UI...
- return true;
- case R.id.action_favorite:
- // User chose the "Favorite" action, mark the current item
- // as a favorite...
- return true;
- default:
- // If we got here, the user's action was not recognized.
- // Invoke the superclass to handle it.
- return super.onOptionsItemSelected(item);
- }
- }
- }
- /*
- aqui pongo otro fichero xml
- androidmanifest.xml
- */
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.techcomputerworld.tcw.test_menu">
- <application
- 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/Theme.AppCompat.Light.NoActionBar">
- <!--android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"-->
- <activity android:name=".MainActivity"
- android:parentActivityName=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- Esta claro que en algun sitio esta el error, si pudierais revisarlo porque fijo que es un error tonto de novato.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement