android 建立項目中去掉標題列,android建立項目

來源:互聯網
上載者:User

android 建立項目中去掉標題列,android建立項目

1.建立new android application project

  theme選none 並打鉤建立一個Blank Activity

 運行如所示:

2。若想把標題列去掉,更改Manifestr的MainActivity 主題樣式

>styles.xml中改

開始將<style name="AppTheme" parent="AppBaseTheme">

改為:<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">//無標題白色背景

去行,閃退並報錯:Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

3。原因,是由於public class MainActivity extends ActionBarActivity在建立的時候繼承了ActionBarActivity有標題的類,這樣就會報錯

更改繼承FragmentActivity並把相應提示報錯處理一下就可以。

具體代碼如下:

 1 package com.example.abc; 2  3 import android.support.v7.app.ActionBarActivity; 4 import android.support.v7.app.ActionBar; 5 import android.support.v4.app.Fragment; 6 import android.support.v4.app.FragmentActivity; 7 import android.os.Bundle; 8 import android.view.LayoutInflater; 9 import android.view.Menu;10 import android.view.MenuItem;11 import android.view.View;12 import android.view.ViewGroup;13 import android.os.Build;14 15 public class MainActivity extends FragmentActivity {16 17     @Override18     protected void onCreate(Bundle savedInstanceState) {19         super.onCreate(savedInstanceState);20         setContentView(R.layout.activity_main);21 22         if (savedInstanceState == null) {23             getSupportFragmentManager().beginTransaction()24                     .add(R.id.container, new PlaceholderFragment()).commit();25         }26     }27 28 //    @Override29 //    public boolean onCreateOptionsMenu(Menu menu) {30 //31 //        // Inflate the menu; this adds items to the action bar if it is present.32 //        getMenuInflater().inflate(R.menu.main, menu);33 //        return true;34 //    }35 //36 //    @Override37 //    public boolean onOptionsItemSelected(MenuItem item) {38 //        // Handle action bar item clicks here. The action bar will39 //        // automatically handle clicks on the Home/Up button, so long40 //        // as you specify a parent activity in AndroidManifest.xml.41 //        int id = item.getItemId();42 //        if (id == R.id.action_settings) {43 //            return true;44 //        }45 //        return super.onOptionsItemSelected(item);46 //    }47 48     /**49      * A placeholder fragment containing a simple view.50      */51     public static class PlaceholderFragment extends Fragment {52 53         public PlaceholderFragment() {54         }55 56         @Override57         public View onCreateView(LayoutInflater inflater, ViewGroup container,58                 Bundle savedInstanceState) {59             View rootView = inflater.inflate(R.layout.fragment_main, container,60                     false);61             return rootView;62         }63     }64 65 }

運行正確:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.