之第六篇,三星拍照崩溃修改解决

时间:2019-09-18 15:50来源: 操作系统
开始贴代码 布局文件1: activity调用相机的类 android:name="com.example.camera.MainActivity" android:label="@string/app_name" --这个在所有调用相机的类里都要设置- android:configChanges="screenSize|keyboardHidden

开始贴代码

布局文件1:

 <activity调用相机的类 android:name="com.example.camera.MainActivity" android:label="@string/app_name" <--这个在所有调用相机的类里都要设置-> android:configChanges="screenSize|keyboardHidden|orientation" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity 中间类不绘制布局 android:name="com.example.camera.UseCameraActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|navigation" android:launchMode="singleTop" android:screenOrientation="portrait" />

布局文件2:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:gravity="center" android:padding="15dp" > <ImageView android: android:layout_width="wrap_content" android:layout_height="100dp" android:layout_marginRight="10dp" android:layout_weight="1" android:src="@drawable/add_id_card_1" /> <ImageView android: android:layout_width="wrap_content" android:layout_height="100dp" android:layout_marginLeft="10dp" android:layout_weight="1" android:src="@drawable/add_id_card_1" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center" android:padding="15dp" > <ImageView android: android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginRight="10dp" android:layout_weight="1" android:src="@drawable/add_id_card_1" /> <ImageView android: android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginLeft="10dp" android:layout_weight="1" android:src="@drawable/add_id_card_1" /> </LinearLayout> </LinearLayout></LinearLayout>

最近通过学习,对fragment的使用有了新的认识。

相机调用中间类

/** * 照片生成的目录在 sd卡的/a/image/camera/.. .jpg * * @author baozi * */public class UseCameraActivity extends Activity {private String mImageFilePath;public static final String IMAGEFILEPATH = "ImageFilePath";public final static String IMAGE_PATH = "image_path";static Activity mContext;public final static int GET_IMAGE_REQ = 5000;private static Context applicationContext;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//判断 activity被销毁后 有没有数据被保存下来if (savedInstanceState != null) {mImageFilePath = savedInstanceState.getString(IMAGEFILEPATH);Log.i("123---savedInstanceState", mImageFilePath);File mFile = new File(IMAGEFILEPATH);if (mFile.exists {Intent rsl = new Intent();rsl.putExtra(IMAGE_PATH, mImageFilePath);setResult(Activity.RESULT_OK, rsl);Log.i("123---savedInstanceState", "图片拍摄成功");finish();} else {Log.i("123---savedInstanceState", "图片拍摄失败");}}mContext = this;applicationContext = getApplicationContext();if (savedInstanceState == null) {initialUI();}}public void initialUI() {//根据时间生成 后缀为 .jpg 的图片long ts = System.currentTimeMillis();mImageFilePath = getCameraPath() + ts + ".jpg";File out = new File(mImageFilePath);showCamera;}private void showCamera {Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile; // setstartActivityForResult(intent, GET_IMAGE_REQ);}@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent intent) {if (GET_IMAGE_REQ == requestCode && resultCode == Activity.RESULT_OK) {Intent rsl = new Intent();rsl.putExtra(IMAGE_PATH, mImageFilePath);mContext.setResult(Activity.RESULT_OK, rsl);mContext.finish();} else {mContext.finish();}}@Overrideprotected void onDestroy() {super.onDestroy();}@Overrideprotected void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState;outState.putString("ImageFilePath", mImageFilePath + "");}@Overridepublic void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);}@Overrideprotected void onRestoreInstanceState(Bundle savedInstanceState) {super.onRestoreInstanceState(savedInstanceState);}public static String getCameraPath() {String filePath = getImageRootPath() + "/camera/";File file = new File;if (!file.isDirectory {file.mkdirs();}file = null;return filePath;}public static String getImageRootPath() {String filePath = getAppRootPath() + "/image";File file = new File;if (!file.exists {file.mkdirs();}file = null;return filePath;}public static String getAppRootPath() {String filePath = "/a";if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {filePath = Environment.getExternalStorageDirectory() + filePath;} else {filePath = applicationContext.getCacheDir() + filePath;}File file = new File;if (!file.exists {file.mkdirs();}file = null;File nomedia = new File(filePath + "/.nomedia");if (!nomedia.existstry {nomedia.createNewFile();} catch (IOException e) {}return filePath;}/*public boolean onKeyDown(int keyCode, KeyEvent event) {if(keyCode == KeyEvent.KEYCODE_BACK&& event.getAction() == KeyEvent.ACTION_DOWN){ Intent inte =new Intent(UseCameraActivity.this, MainActivity.class);startActivity; return true; } return super.onKeyDown(keyCode, event);}*/}---------

/** * 启动界面 * * 照片生成的目录在 sd卡的/a/image/camera/.. .jpg * * @author baozi * */public class MainActivity extends Activity implements OnClickListener{private Bitmap bitmaps;protected static final int REQCAMERA = 11;private static final String TAG = "MainActivity";private View button1;private ImageView photo_iv;private ContentResolver mContentResolver;final int IMAGE_MAX_SIZE = 1024;private ImageView lifttob,righttob,rightbom,liftbom;private int volue =0;protected static final int ADD_ID_CARD_FRONT = 101;protected static final int ADD_ID_CARD_SIDE = 102;protected static final int ADD_BANK_FRONT = 103;protected static final int ADD_BANK_SIDE = 104;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mContentResolver = getContentResolver();//判断 activity被销毁后 有没有数据被保存下来if (savedInstanceState != null) {volue =savedInstanceState.getInt;Log.i("123---savedInstanceState", "图片拍摄成功");finish();} else {Log.i("123---savedInstanceState", "图片拍摄失败");}init();}private void init(){lifttob = (ImageView) findViewById(R.id.btn_real_name_authentication_add_id_card_front);righttob = (ImageView) findViewById(R.id.btn_real_name_authentication_add_id_card_side);liftbom = (ImageView) findViewById(R.id.btn_bank_front);rightbom = (ImageView) findViewById(R.id.btn_bank_side);lifttob.setOnClickListener;righttob.setOnClickListener;rightbom.setOnClickListener;liftbom.setOnClickListener;}@Overridepublic void onClick {// TODO Auto-generated method stubswitch ) {//按钮启动相机 volue赋值case R.id.btn_real_name_authentication_add_id_card_front:volue=1;Intent intent = new Intent(MainActivity.this,UseCameraActivity.class);startActivityForResult(intent, ADD_ID_CARD_FRONT);break;case R.id.btn_real_name_authentication_add_id_card_side:volue =2;Intent intent1 = new Intent(MainActivity.this,UseCameraActivity.class);startActivityForResult(intent1, ADD_ID_CARD_SIDE);break;case R.id.btn_bank_front:volue =3;Intent intent2 = new Intent(MainActivity.this,UseCameraActivity.class);startActivityForResult(intent2, ADD_BANK_FRONT);break;case R.id.btn_bank_side:volue =4;Intent intent3 = new Intent(MainActivity.this,UseCameraActivity.class);startActivityForResult(intent3, ADD_BANK_SIDE);break;default:break;}}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {switch (requestCode) {case ADD_ID_CARD_FRONT:if{String path = data.getStringExtra(UseCameraActivity.IMAGE_PATH);Log.i("123", path);// 根据照片的位置获取图片Bitmap bitmap = getBitmap;Drawable dra = new BitmapDrawable;lifttob.setImageBitmap;}break;case ADD_ID_CARD_SIDE:if{String path1 = data.getStringExtra(UseCameraActivity.IMAGE_PATH);Bitmap bitmap1 = getBitmap;righttob.setImageBitmap;}case ADD_BANK_FRONT:if{String path2 = data.getStringExtra(UseCameraActivity.IMAGE_PATH);Bitmap bitmap2 = getBitmap;liftbom.setImageBitmap;}case ADD_BANK_SIDE:if{String path3 = data.getStringExtra(UseCameraActivity.IMAGE_PATH);Bitmap bitmap3 = getBitmap;rightbom.setImageBitmap;}break;default:super.onActivityResult(requestCode, resultCode, data);break;}}@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); /* if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { //land } else*/ if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { //port } }private Uri getImageUri(String path) {return Uri.fromFile(new File;}private Bitmap getBitmap(String path) {Uri uri = getImageUri;InputStream in = null;try {in = mContentResolver.openInputStream;// Decode image sizeBitmapFactory.Options o = new BitmapFactory.Options();o.inJustDecodeBounds = true;BitmapFactory.decodeStream(in, null, o);in.close();//根据图片尺寸设置屏幕显示大小 o2.inSampleSize = scale; 也可以设置固定值 比如10int scale = 1;if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {scale =  Math.pow Math.round(Math.log(IMAGE_MAX_SIZE/  Math.max(o.outHeight, o.outWidth))/ Math.log;}BitmapFactory.Options o2 = new BitmapFactory.Options();o2.inSampleSize = scale;in = mContentResolver.openInputStream;Bitmap b = BitmapFactory.decodeStream(in, null, o2);in.close();return b;} catch (FileNotFoundException e) {Log.e(TAG, "file " + path + " not found");} catch (IOException e) {Log.e(TAG, "file " + path + " not found");}return null;}//存入调用相机设置的volue值 为了防止图片设置重复@Overrideprotected void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState;outState.putInt("volue", volue );}}

demo下载地址:

一开始接触android的时候,很是受不了这个fragment,总感觉它把一个简单的事情搞复杂啦,所以每次新建工程的时候总是固执的选择empty Activity

有问题欢迎学习交流,私信留言,共同学习

但是后来发现这样写出来的代码移植的时候总是要该来该去,现在开始偏爱带fragment的工程向导

向导默认生成一个JAVA文件,和两个布局文件

MainActivity.JAVA

package com.example.tesf;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

布局文件:activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.tesf.MainActivity"
    tools:ignore="MergeRootFrame" />

另外一个布局文件:fragment_main.xml  这个布局文件就可以自己发挥啦

下面演示一个登录注册的功能:

图片 1

在fragment_main.xml实现登录注册的布局

图片 2图片 3

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff2f0eb"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="@dimen/height_top_bar"
        android:layout_weight="0"
        android:background="@color/common_top_bar_blue" >

        <TextView
            android:id="@+id/ivTitleName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="登录"
            android:textColor="#ffffffff"
            android:textSize="20.0sp" />
        <ImageButton
            android:id="@+id/ivTitleBtnLeft1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@drawable/top_icon_back" />
         <ImageButton
            android:id="@+id/ivTitleBtnLeft2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:visibility="gone"
            android:background="@drawable/top_icon_menu" />

         <TextView
            android:id="@+id/ivTextViewRigh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:textColor="#ffffffff"
            android:textSize="16.0sp"
            android:text="忘记密码"
            android:clickable="true" />

    </RelativeLayout>

    <ViewFlipper 
        android:id="@+id/mainFlipper"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >
          <LinearLayout 
            android:id="@+id/content1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:background="@color/login_background"
            android:orientation="vertical" >
                <LinearLayout
                    android:layout_margin="10dp" 
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="vertical" >
                       <LinearLayout 
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:orientation="horizontal" 
                            android:background="@drawable/inputbox_bg">
                            <ImageView 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:src="@drawable/input_phone"    
                                />  
                            <EditText 
                                android:id="@+id/login_number"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="6"
                                android:inputType="phone"
                                android:background="@null"                            
                                android:textSize="15.0sp"
                                android:hint="手机号">
                                 <requestFocus />
                            </EditText>                                                  
                        </LinearLayout>

                       <LinearLayout 
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:orientation="horizontal"
                            android:layout_marginTop="15dp" 
                            android:background="@drawable/inputbox_bg">
                            <ImageView 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:src="@drawable/input_key"    
                                />  
                            <EditText 
                                android:id="@+id/login_passward"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:inputType="textPassword"
                                android:layout_weight="6"
                                android:background="@null"                            
                                android:textSize="15.0sp"
                                android:hint="密码"/>                                                                      
                        </LinearLayout>                      
                </LinearLayout>
                 <Button
                    android:id="@+id/loadBtn"
                    style="@style/style_common_btn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:background="@drawable/selector_common_btn"
                    android:text="登录" />

                <TextView 
                     android:id="@+id/regster_text"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_margin="8dp"
                     android:clickable="true"
                     android:textColor="@color/common_top_bar_blue"
                     android:text="立即注册"
                    />
          </LinearLayout>


           <LinearLayout 
                android:id="@+id/content2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_horizontal"
                android:background="@color/login_background"
                android:orientation="vertical" >
                  <LinearLayout 
                android:id="@+id/content2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_horizontal"
                android:background="@color/login_background"
                android:orientation="vertical" >
                 <LinearLayout
                    android:layout_margin="10dp" 
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:orientation="vertical" >
                       <LinearLayout 
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:orientation="horizontal" 
                            android:background="@drawable/inputbox_bg">
                            <TextView 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textColor="@color/common_top_bar_blue"
                                android:text="手机号"    
                                />  
                            <EditText 
                                android:id="@+id/register_number"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="6"
                                android:inputType="phone"
                                android:background="@null"                            
                                android:textSize="15.0sp"
                                android:hint="请输入手机号作为用户名">
                                 <requestFocus />
                            </EditText>                                                  
                        </LinearLayout>
                       <ImageView 
                           android:layout_margin="10dp"
                           android:layout_width="match_parent"
                           android:layout_height="1dp"
                           android:background="@color/login_background"
                           />
                       <LinearLayout 
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:orientation="horizontal" 
                            android:background="@drawable/inputbox_bg">
                            <TextView 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:textColor="@color/common_top_bar_blue"
                                android:text="设置密码"    
                                />  
                            <EditText 
                                 android:id="@+id/register_passward"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="6"
                                android:inputType="textPassword"
                                android:background="@null"                            
                                android:textSize="15.0sp"
                                android:hint="请输入至少6位密码"/>                                                                     
                        </LinearLayout>
                      <ImageView
                       android:layout_margin="10dp" 
                       android:layout_width="match_parent"
                       android:layout_height="1dp"
                       android:background="@color/login_background"
                       />
                      <LinearLayout 
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" 
                        android:background="@drawable/inputbox_bg">
                        <TextView 
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textColor="@color/common_top_bar_blue"
                            android:text="验证码"    
                            />  
                        <EditText 
                            android:id="@+id/register_code"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:inputType="number"
                            android:background="@null"                            
                            android:textSize="15.0sp"
                            android:textColor="@color/login_background"
                            android:text="0"/>    
                        <Button
                            android:id="@+id/get_code"
                            style="@style/style_common_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:layout_margin="5dp"
                            android:background="@drawable/selector_common_btn"
                            android:text="获取验证码" />                                                                        
                        </LinearLayout>                                    
                </LinearLayout>    
               <Button
                   android:id="@+id/confirm_button"
                   style="@style/style_common_btn"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_margin="10dp"
                   android:background="@drawable/selector_common_btn2"
                   android:text="确定" />                                              
        </LinearLayout>

        </LinearLayout>



    </ViewFlipper>


</LinearLayout>

View Code

新建一个类实现登录注册的逻辑

图片 4图片 5

package com.example.tesf;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class RegiserLogin extends Fragment{

    private ImageButton ib_back;
    private ImageButton ib_menu;
    private TextView regster_text;//
    private TextView ivTitleName;
    private TextView ivTextViewRigh;
    private ViewFlipper vf;    
    private Button confirm_button;
    private Button load_btn;    
    private EditText login_number;
    private EditText login_passward;
    private EditText register_number;
    private EditText register_passward;
    private EditText register_code;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_main, container, false);
          initView(rootView);
          return rootView;
    }
    private void initView(View view){
        vf = (ViewFlipper) view.findViewById(R.id.mainFlipper);
        ib_menu = (ImageButton) view.findViewById(R.id.ivTitleBtnLeft2);
        ib_back = (ImageButton) view.findViewById(R.id.ivTitleBtnLeft1);

        regster_text = (TextView) view.findViewById(R.id.regster_text);
        ivTitleName = (TextView) view.findViewById(R.id.ivTitleName);

        confirm_button = (Button) view.findViewById(R.id.confirm_button);
        load_btn = (Button) view.findViewById(R.id.loadBtn);

        login_number = (EditText) view.findViewById(R.id.login_number);
        login_passward = (EditText) view.findViewById(R.id.login_passward);
        register_number = (EditText) view.findViewById(R.id.register_number);
        register_passward = (EditText) view.findViewById(R.id.register_passward);
        register_code = (EditText) view.findViewById(R.id.register_code);


        ib_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {                
//                finish();
            }
        });

       regster_text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ib_menu.setVisibility(View.VISIBLE);
            ivTitleName.setText("注册新账号");
            vf.showNext();
            ib_back.setVisibility(View.GONE);
        }
       });

      ib_menu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ib_back.setVisibility(View.VISIBLE);
            ivTitleName.setText("登录");
            vf.showPrevious();
            ib_menu.setVisibility(View.GONE);

        }
      });


    }

}

View Code

实现登录注册功能只需要在向导生成的MainActivity里稍加改动就行

if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new RegiserLogin())
                    .commit();
}

其实在学习Android的过程中都可以仿照这种模式,在向导生成代码的基础上,自己创建extends Fragment的类,再建一个该类需要用的布局文件。

这样所有的demo都可以在一个工程下完成啦。

 

编辑: 操作系统 本文来源:之第六篇,三星拍照崩溃修改解决

关键词: