Android Sliding Drawer Open On Create

前端 未结 2 1790
灰色年华
灰色年华 2021-01-23 23:38

I want to have a slider that is open when the app starts. It will be open with buttons and such and when the user closes it, there will be more buttons to access. Is this possib

2条回答
  •  伪装坚强ぢ
    2021-01-24 00:23

    XML Layout - In a basic LinearLayout:

      
    
        
    
            
    
            

    And your Activity will looks like this:

    public class Home extends Activity implements OnDrawerScrollListener
    {
    
    private ImageView               handleImage;
    private Button                  handleButton;
    private SlidingDrawer           slide;
        private TextView                tv_commentDisplay;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
    
                tv_commentDisplay = (TextView)this.findViewById(R.id.tv_commentDisplay);
        handleImage = (ImageView)this.findViewById(R.id.handleImage);
        handleButton = (Button)this.findViewById(R.id.handleButton);
        slide = (SlidingDrawer)this.findViewById(R.id.slide);
    
        slide.open(); // not sure
        slide.setOnDrawerScrollListener(this);
    
        handleButton = ((Button)this.findViewById(R.id.handleButton));
    
        tv_commentDisplay.setText("Hello World");
    }
    
    @Override
    public void onScrollEnded() {
    }
    
    @Override
    public void onScrollStarted() {
        if (slide.isOpened())
            handleImage.setImageResource(R.drawable.ic_tray_collapse);
        else {
            handleImage.setImageResource(R.drawable.ic_tray_expand);
        }
    }
    

提交回复
热议问题