Android uygulamaları geliştirmeyi öğreniyorum ve bir araç çubuğu kullanan ve eylem çubuğuna entegre eden çekmece şablonunu kullanıyorum. Ben çekmece ve eylem çubuğu eylemleri olan bir ana java dosyası yapmaya çalıştığınızda karşılaştığım sorun oluşur. Daha sonra, her bir gerçek düzen, gerekli faaliyetleri gerçekleştirmek için ana dosyadan uzanacaktır.Android Studio Araç Çubuğu, Action Çubuğu olarak
İlk olarak, sahip olduğum hata budur. 10:
03-30 23 24,895 22105-22105/com.mmaengineer.runique E/AndroidRuntime: önemli özel durum: Ana Proses: com.mmaengineer.runique PID: 22105 java.lang.RuntimeException:
Etkinlik başlatılamadı ComponentInfo {com.mmaengineer.runique/com.mmaengineer.runique.MainActivity}: java.lang.IllegalStateException: Bu Etkinlik zaten pencere dekoru tarafından sağlanan bir eylem çubuğuna sahiptir. Window.FEATURE_SUPPORT_ACTION_BAR isteğinde bulunmayın ve bunun yerine bir Araç Çubuğu kullanmak için windowActionBar öğesini temanızda false olarak ayarlayın.
Nedeni: java.lang.IllegalStateException: Bu Etkinlik zaten pencere dekoru tarafından sağlanan bir eylem çubuğuna sahiptir. Window.FEATURE_SUPPORT_ACTION_BAR isteğinde bulunmayın ve bunun yerine bir Araç Çubuğu kullanmak için windowActionBar öğesini temanızda false olarak ayarlayın. android.support.v7.app.AppCompatActivity.setSupportActionBar de android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar (AppCompatDelegateImplV7.java:197) (AppCompatActivity.java:129)
Bildiri dosya
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/app_name_settings">
</activity>
</application>
MainActivity.java
public class MainActivity extends MainControls {
public static final int TL = Toast.LENGTH_SHORT; // Toast.LENGTH_LONG for longer
public SharedPreferences mPrefs;
public String gameMode;
public String double_xp;
@Override
protected void onCreate(Bundle savedInstanceState) {
mPrefs = getSharedPreferences("LSprefs", 0);
gameMode = mPrefs.getString("gameMode", "");
double_xp = mPrefs.getString("double_xp", "");
if (gameMode == "") {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
((TextView)findViewById(R.id.textView2)).setText(gameMode);
((TextView)findViewById(R.id.textView3)).setText(double_xp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MainControls.java
public class MainControls extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Bunu yaptı. Varsayılan şablon olduğu için bir sıçrama ekranı eklediğimde bunun neden sadece bir sorun haline geldiğinden emin değilim. Ama bu işe yaramış görünüyor. Teşekkürler! – user2928301
Android Studio'nun oluşturduğu dosyalardan bunu neden aldığınızı bilmediğinizden, belki de bir tür proje oluşturdunuz ve ardından ana Etkinliği değiştirdiniz mi? Her neyse, işe yaradığına sevindim, sana yardımcı olan cevaplardan birini kabul etmeyi düşün. – BadCash