美文网首页
继承AppCompatActivity或Activity时,标题

继承AppCompatActivity或Activity时,标题

作者: 小小程序员jh | 来源:发表于2018-10-10 19:23 被阅读151次

    Android 开发中容易忽略的点:

     android.util.AndroidRuntimeException: requestFeature() must be called before adding content                            
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2319)                           
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2370)                            
        at android.app.ActivityThread.access$800(ActivityThread.java:155)                           
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)                             
        at android.os.Handler.dispatchMessage(Handler.java:102)         
    
    public class MainActivity extends Activity {     
      @Override 
      protected void onCreate(Bundle savedInstanceState) {               
          super.onCreate(savedInstanceState);               
          requestWindowFeature(Window.FEATURE_NO_TITLE); 
          // 这行为隐藏标题栏               
          setContentView(R.layout.activity_main); 
      }
    }
    
    // 继承AppCompatActivity时:   
       @Override    
       protected void onCreate(Bundle savedInstanceState) {      
        super.onCreate(savedInstanceState);       
         
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);       
        /** * 去掉系统自带的标题栏*/      
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);      
         // 因为是继承自AppCompatActivity, 所以要加上下面几句代码才能管用       
        if (getSupportActionBar() != null){          
             getSupportActionBar().hide();       
         }       
             setContentView(R.layout.activity_main);   
       }
    

    相关文章

      网友评论

          本文标题:继承AppCompatActivity或Activity时,标题

          本文链接:https://www.haomeiwen.com/subject/idemaftx.html