diff --git a/app/build.gradle b/app/build.gradle index e3525e8..0a9d1fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,4 +27,5 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' api 'com.hankcs:hanlp:portable-1.7.2' + implementation 'com.google.android.material:material:1.0.0' } diff --git a/app/src/main/java/com/example/cmknowledgegraph/MainActivity.java b/app/src/main/java/com/example/cmknowledgegraph/MainActivity.java index bf0a7ce..6cdaf56 100644 --- a/app/src/main/java/com/example/cmknowledgegraph/MainActivity.java +++ b/app/src/main/java/com/example/cmknowledgegraph/MainActivity.java @@ -1,19 +1,77 @@ package com.example.cmknowledgegraph; -import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; +import com.example.cmknowledgegraph.MainContent; +import com.example.cmknowledgegraph.R; +import com.example.cmknowledgegraph.SearchContent; +import com.google.android.material.bottomnavigation.BottomNavigationView; import com.hankcs.hanlp.HanLP; +import androidx.appcompat.app.AppCompatActivity; +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +import android.view.MenuItem; +import android.widget.TextView; + +import java.util.List; + public class MainActivity extends AppCompatActivity { + private TextView mTextMessage; + private FragmentTransaction transaction; + private FragmentManager fragmentManager; + + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener + = new BottomNavigationView.OnNavigationItemSelectedListener() { + + @Override + + + public boolean onNavigationItemSelected(MenuItem item) { + fragmentManager = getSupportFragmentManager(); //使用fragmentmanager和transaction来实现切换效果 + transaction = fragmentManager.beginTransaction(); + switch (item.getItemId()) { + case R.id.home: + transaction.replace(R.id.content,new MainContent()); //对应的java class + transaction.commit(); //一定不要忘记commit,否则不会显示 + return true; + case R.id.search: + transaction.replace(R.id.content,new SearchContent()); //对应的java class + transaction.commit(); //一定不要忘记commit,否则不会显示 + return true; + case R.id.chat: + return true; + case R.id.person: + return true; + } + return false; + } + + }; + + // 设置默认进来是tab 显示的页面 + private void setDefaultFragment(){ + fragmentManager = getSupportFragmentManager(); + transaction = fragmentManager.beginTransaction(); + transaction.replace(R.id.content,new MainContent()); + transaction.commit(); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - System.out.println("hello"); - System.out.println(HanLP.segment("你好,欢迎使用HanLP汉语处理包!")); - System.out.println("haha"); + //setDefaultFragment(); //上面写的那个函数 + BottomNavigationView navView = findViewById(R.id.nav_view); + mTextMessage = findViewById(R.id.message); + navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + + //HanLP测试 + String content = "发烧感冒"; + List keywordList = HanLP.extractKeyword(content, 5); + System.out.println(keywordList); } + } diff --git a/app/src/main/java/com/example/cmknowledgegraph/MainContent.java b/app/src/main/java/com/example/cmknowledgegraph/MainContent.java new file mode 100644 index 0000000..b9182bd --- /dev/null +++ b/app/src/main/java/com/example/cmknowledgegraph/MainContent.java @@ -0,0 +1,19 @@ +package com.example.cmknowledgegraph; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; + +public class MainContent extends Fragment { + + //创建视图 + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate( R.layout.activity_main, container, false ); //要加载的layout文件 + } +} diff --git a/app/src/main/res/drawable/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/drawable/ic_launcher_background.xml deleted file mode 100644 index 0d025f9..0000000 --- a/app/src/main/res/drawable/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/drawable/search_back.jpg b/app/src/main/res/drawable/drawable/search_back.jpg deleted file mode 100644 index c9440f1..0000000 Binary files a/app/src/main/res/drawable/drawable/search_back.jpg and /dev/null differ diff --git a/app/src/main/res/drawable/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml similarity index 100% rename from app/src/main/res/drawable/drawable/ic_dashboard_black_24dp.xml rename to app/src/main/res/drawable/ic_dashboard_black_24dp.xml diff --git a/app/src/main/res/drawable/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml similarity index 100% rename from app/src/main/res/drawable/drawable/ic_home_black_24dp.xml rename to app/src/main/res/drawable/ic_home_black_24dp.xml diff --git a/app/src/main/res/drawable/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml similarity index 100% rename from app/src/main/res/drawable/drawable/ic_notifications_black_24dp.xml rename to app/src/main/res/drawable/ic_notifications_black_24dp.xml diff --git a/app/src/main/res/drawable/drawable/person.png b/app/src/main/res/drawable/person.png similarity index 100% rename from app/src/main/res/drawable/drawable/person.png rename to app/src/main/res/drawable/person.png diff --git a/app/src/main/res/drawable/drawable/search.png b/app/src/main/res/drawable/search.png similarity index 100% rename from app/src/main/res/drawable/drawable/search.png rename to app/src/main/res/drawable/search.png diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml new file mode 100644 index 0000000..b425c77 --- /dev/null +++ b/app/src/main/res/menu/bottom_nav_menu.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + +