簡體   English   中英

我在一項活動中有 2 個按鈕。 當我點擊它們時,我會創建新的意圖,這樣我就可以創建一個新的屏幕。 一個有效,另一個無效

[英]I have 2 buttons in one activity. When I click on them, I make new intents so I can make a new screen. One works, the other doesn't

我的Java代碼

 Button equations = (Button) findViewById(R.id.algebrabutton);
    equations.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), 
             algebra_activity.class);
            startActivityForResult(myIntent, 0);
        }
    });


    Button word = (Button) findViewById(R.id.wordbutton);
    word.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view1) {
            Intent myIntent1 = new Intent(view1.getContext(), 
               word_activity.class);
            startActivityForResult(myIntent1, 0);
        }
    });

錯誤日志

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lawrencej.mathappdeluxe/com.exampl‌​e.lawrencej.mathappd‌​eluxe.algebra_activi‌​ty}: 
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor.
Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead

當我單擊單詞按鈕時,它工作正常並顯示一個新屏幕。 當我單擊方程式按鈕時,應用程序崩潰。 難道我做錯了什么?

在您的styles代碼中使用它。

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

在你的manifest

<activity
    android:name=".algebra_activity"
    android:theme="@style/AppTheme.NoActionBar">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM