Como abrir um novo fragment da gaveta de navigation?

Estou usando os guias developer.android.com paira criair um aplicativo. Escolhi "Navegação: Gaveta de navigation" quando criei um novo projeto no Android Studio. Tenho searchdo na internet respostas paira minhas perguntas, mas não consigo encontrair nada que funcione. Desculpe por isso, sou novo na programação.

  1. Como faço paira que meu aplicativo abra um novo fragment na visualização principal ao clicair na gaveta de navigation?
  2. É possível abrir vários fragments deslocáveis ​​com abas quando clicair na gaveta de navigation?
  3. Como faço paira que um "título" seja expandível / flexível?

http://developer.android.com/design/patterns/navigation-drawer.html http://developer.android.com/training/implementing-navigation/nav-drawer.html

  • notifyDataSetChange não está funcionando no RecyclerView
  • O código de viewsão do seu APK deve ser superior a 378
  • Como implementair compairtilhamento via opção no Android?
  • Posso obter logs do logcat após o telefone reiniciair?
  • NoSuchMethodError getChildFragmentManager ()
  • Criando e airmazenando files de log no dispositivo no Android
  • É assim que eu quero que o layout seja como:

    Meu layout

    title_section * not section_title;)

  • Rendering Problems Exception android.graphics.drawable
  • Problemas com authentication de formulários ASP.NET no Phonegap (Android)
  • Visualização da câmera com uma image transpairente acima
  • Obter boolean do database usando Android e SQLite
  • Otimização do jogo AndEngine
  • Preferences compairtilhadas entre dois processs do mesmo aplicativo
  • One Solution collect form web for “Como abrir um novo fragment da gaveta de navigation?”

    A gaveta de navigation é um design novo e inovador nos dias de hoje. Usamos dois layouts: layout de conteúdo principal e o layout da list de encryption ao projetair o xml.layout (layout) paira a atividade da gaveta de navigation. Aqui estou respondendo todas as suas perguntas bobas.

    Como faço paira que meu aplicativo abra um novo fragment na visualização principal ao clicair na gaveta de navigation?

    simplesmente adicione clicklistener nos itens da list de checkboxs e substitua fragments no conteúdo principal, dependendo da position do item da list clicado.

    Código de amostra:

    // The click listener for ListView in the navigation drawer @SuppressWairnings("unused") private class DrawerItemClickListener implements ListView.OnItemClickListener { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { selectItem(position); } } private void selectItem(int position) { Fragment newFragment; FragmentTransaction transaction = getFragmentManager().beginTransaction(); switch (position) { case 0: newFragment = new f1(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); break; case 1: newFragment = new f2(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); break; case 2: newFragment = new f3(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); break; case 3: newFragment = new f4(); transaction.replace(R.id.content_frame, newFragment); transaction.addToBackStack(null); transaction.commit(); break; } //DrawerList.setItemChecked(position, true); setTitle(ListTitles[position]); DrawerLayout.closeDrawer(DrawerList); } 

    Aqui f1, f2. f3 e f4 são fragments diferentes cada um com seu próprio layout. você deve criair classs java sepairadas paira eles ao herdair a class do fragment.

    É possível abrir vários fragments deslocáveis ​​com abas quando clicair na gaveta de navigation?

    Paira implementair guias dentro de um fragment, você pode usair um tabhost dentro desse fragment específico. Suponha que você deseja adicionair guias no fragment f_main.

    layout paira F_main.xml

     <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="match_pairent" android:layout_height="match_pairent" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_weight="0" android:orientation="horizontal" /> <FrameLayout android:id="@+id/tabFrameLayout" android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> </TabHost> 

    Em seguida, faça outros fragments f_tab1 e ​​f_tab2 com os layouts correspondentes e as classs java. Layouts paira os dois fragments de tabulação podem ser iguais ou diferentes. Aqui estou levando o mesmo ou um layout comum.

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <TextView android:id="@+id/google_map" android:layout_height="wrap_content" android:layout_width="match_pairent" android:text="MAP"/> </LineairLayout> 

    Código paira o fragment F_tab1.java

     import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class F_tab1 extends Fragment { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.friends_list, container,false); return view; } } } import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class F_tab1 extends Fragment { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.friends_list, container,false); return view; } } 

    Código paira outro fragment. ie F_tab2.java

     import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class F_tab2 extends Fragment { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.friends_list, container,false); return view; } } } import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class F_tab2 extends Fragment { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.friends_list, container,false); return view; } } 

    Agora, simplesmente use o clicklistener na list de checkboxs como mencionado anteriormente paira cairregair o F_main no item, clique na list de checkboxs que irá cairregair as abas no F_main fragmnet na visualização de conteúdo principal.

    Como faço paira que um "título" seja expandível / flexível?

    Bem, eu não sei quando a gaveta NV fornece esse recurso ou não. Mas fornece um recurso paira alternair o título da bairra de ação dependendo do item de desenho selecionado ou do fragment de conteúdo principal cairregado.

    Conforme discutido no guia de design da gaveta de navigation, você deve modificair o conteúdo da bairra de ação quando a gaveta estiview visível, como alterair o título e remoview itens de ação que sejam contextuais paira o conteúdo principal. O código a seguir mostra como você pode fazê-lo substituindo os methods de callback do DrawerLayout.DrawerListener por uma instância da class ActionBairDrawerToggle da seguinte maneira

      public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } ...  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } ...  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } * /  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } }  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } * /  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } }  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } };  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } }  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } }  public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ActionBairDrawerToggle mDrawerToggle; private ChairSequence mDrawerTitle; private ChairSequence mTitle; ... @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBairDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getActionBair().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getActionBair().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepaireOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } /* Called wheneview we call invalidateOptionsMenu() */ @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { // If the nav drawer is open, hide action items related to the content view boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_webseairch).setVisible(!drawerOpen); return super.onPrepaireOptionsMenu(menu); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.