"黑科技" - Eclipse使用RecyclerView

之所以取名“黑科技”,因为现在主流就是使用Android Studio,Eclipse主要是用来维护旧项目,还有就是现在想在Eclipse使用新5.+功能真的不方便,我是搞了N遍才OK了的。网上还好少人聊这个?我自己记录一下

  • 拷贝adt-bundle-linux-x86_64-20140702/sdk/extras/android/support/v7/appcompat/opt/adt-bundle-linux-x86_64-20140702/sdk/extras/android/support/v7/recyclerview到自己目录下

  • project.properties添加Library

android.library.reference.1=../appcompat
android.library.reference.2=../recyclerview
  • values目录添加colors.xml,内容如下

<resources>
    <color name="colorPrimary">#67cc26color>
    <color name="colorPrimaryDark">#67cc26color>
    <color name="colorAccent">#67cc26color>
resources>
  • values目录下styles.xml内容修改为:


    -- Base application theme. -->
    

    

    
  • AndroidManifest.xml内容

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.recyclerviewdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="22" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
        activity>
    application>

manifest>

变更Theme为android:theme="@style/AppTheme.NoActionBar"

  • activity_main.xml
"http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_dark"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.recyclerviewdemo.MainActivity" >

    "@+id/recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
  • MainActivity.java测试内容
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d("xujie", "AppCompatActivity Success."); 
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    Log.d("xujie", "RecyclerView Success."); 
}

@Override
protected void onResume() {
    super.onResume();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        View decorView = getWindow().getDecorView();
        // Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY //
//                    | View.SYSTEM_UI_FLAG_IMMERSIVE //
                ;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

示例源码

你可能感兴趣的:(Android,开发)