-1 голос
 
922 просмотра
4.06.2019 / 12:41  MasterOS

Как добавить NavigationDrawer в MainActivity?

Всем привет! Как я добавляю навигатион-дравер на MainActivity? Например, на MainActivity это вебвиев и нужен добавить его дравер.
Нужен вот так результат:
Изм. aNNiMON от 4.06.2019 / 20:18
Ответы
 
1 голос
 
# 5.06.2019 / 16:43  vlavolk
https://developer.android.com/..._a_navigation_drawer
 
0 голосов
 
# 5.06.2019 / 14:58  SuperSystem
Можно сделать так:

MainActivity

  1. import android.app.*;
  2. import android.os.*;
  3. import android.webkit.*;
  4. import android.view.ViewGroup.*;
  5.  
  6. public class MainActivity extends Activity
  7. {
  8.  
  9.  private WebView wv;
  10.  private DrawerView dv;
  11.  
  12.  public void onCreate(Bundle b){
  13.   super.onCreate(b);
  14.  
  15.   wv = (WebView) findViewById(R.id.webView);
  16.   dv = new DrawerView(this);
  17.  
  18.   // и
  19.   //  это
  20.  
  21.   RelativeLayout rl = new RelativeLayout(this);
  22.   rl.addView(wv);
  23.   rl.addView(dv);
  24.   setContentView(rl);
  25.   ...
  26.  
  27.   // или это
  28.   // как удобней
  29.  
  30.   LayoutParams lp;
  31.  
  32.   ...
  33.  
  34.   setContentView(R.layout.main);
  35.   addContentView(dv,lp);
  36.  
  37.   ...
  38.  
  39.  }
  40.  
  41. }

DrawerView

  1. import android.*;
  2. import android.app.*;
  3. import android.content.*;
  4. import android.widget.*;
  5.  
  6. public class DrawerView extends RelativeLayout
  7. {
  8.  
  9.  private DrawerLayout dl;
  10.  
  11.  public DrawerView(Context c){
  12.   super(c);
  13.  
  14.   dl = (DrawerLayout)findViewById(R.id.drawer_layout);
  15.   this.addView(dl);
  16.  
  17.   //если нужен MainActivity то вот
  18.   Activity a = (Activity)c;
  19.   ...
  20.  }
  21. }
 
-1 голос
 
# 5.06.2019 / 16:38  MasterOS
AndroidManifest.xml:
  1. <activity
  2.             android:label="@string/app_name"
  3.             android:name=".SplashActivity"
  4.             android:theme="@style/AppTheme.Material">
  5.             <intent-filter >
  6.                 <action android:name="android.intent.action.MAIN" />
  7.  
  8.                 <category android:name="android.intent.category.LAUNCHER" />
  9.             </intent-filter>
  10.         </activity>
  11.         <activity
  12.             android:label="@string/app_name"
  13.             android:name=".MainActivity"
  14.             android:theme="@style/AppTheme.Material"/>
  15.         <intent-filter >
  16.             <action android:name="android.intent.action.MAIN" />
  17.  
  18.             <category
  19.                 android:name="android.intent.category.DEFAULT">
  20.  
  21.             </category>
  22.         </intent-filter>
  23.         <activity
  24.             android:label="@string/app_name"
  25.             android:name=".DrawerActivity"
  26.             android:theme="@style/AppTheme.Material"/>
  27.         <intent-filter >
  28.             <action android:name="android.intent.action.MAIN" />
Правильно или android:name="com.test.test.DrawerActivity"?
 
-1 голос
 
# 5.06.2019 / 09:43  MasterOS
Здрасте, вот:
Открыть спойлер
Всего: 4

Реклама

Мы в соцсетях

tw tg yt gt