The process is forced to terminate when the Android toolbar is applied.

Asked 2 years ago, Updated 2 years ago, 27 views

If you apply the toolbar after transferring from one activity to another through start activity, the application will be forcibly terminated due to an unexpected error in the part where the application is executed. Which part is wrong?

public class ServiceActivity extends AppCompatActivity {

    private Toolbar mToolbar;
    String ClientTAG = "Client";
    String OptionTAG = "Option";
    private Context context = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_service);
        mToolbar = (Toolbar) findViewById(R.id.toolBar);
        mToolbar.setTitle("tool test");
        mToolbar.setTitleTextColor(Color.WHITE);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

For the layout, we made a separate toolbar layout and included it in the layout_service and modified the style part.

android

2022-09-22 21:12

1 Answers

Like the person who left a comment, if you have an error message, you can find it right away.

There are two main areas that are expected.

1) If there is no toolbar in layout_service.xml

2) If there is no Action Bar

The code for making the menu doesn't seem to be a big problem.


2022-09-22 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.