ナビゲーション・ドロワーとツールバーでアプリを構築しました。私は、ツールバーの "lable"をクリックして "MainActivity"に戻ることができるように実装したいと思います。MainActivity Android Appに戻る
次Acivityが実行されている、とツールバー上のユーザーがクリックした場合、それはMainActivity
public class Activity_A extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_angebot_erstellen);
}
@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.toolbar) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
return super.onOptionsItemSelected(item);
}
}
マイApp_Bar
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true"
tools:context="blub">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
に彼/彼女を返す必要がありますマニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="blubb">
<uses-permission android:name="android.permission.INTERNET" />
<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"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity_A" />
<activity android:name=".Activity_E" />
<activity android:name=".Login" />
<activity android:name=".Register" >
</activity>
</application>
</manifest>
申し訳ありません私はこれに少し新しくて問題は、lableをクリックしても何も起こらないということです。助けてくれてありがとう。
よろしく:)
あなたのツールバーをあなたのActionBarとして使用しますか? –
ActionBarをクリックするとどういう意味ですか? – TooManyEduardos
私はツールバーをActionBarとして使用したいと思います。混乱のために叫ぶ。 –