分享一個(gè)非常好的新聞客戶端(基于百度數(shù)據(jù))
作者:wgcq 
  基于百度數(shù)據(jù),一個(gè)非常好用的新聞客戶端。
 源碼簡介:基于百度數(shù)據(jù),一個(gè)非常好用的新聞客戶端。
源碼效果:
源碼片段:
- package com.linpeng.baidunewssearch;
 - import java.lang.reflect.Method;
 - import com.linpeng.baidunewssearch.R;
 - import com.linpeng.fragment.FragmentNews;
 - import com.linpeng.fragment.FragmentPhoto;
 - import com.linpeng.fragment.FragmentPostbar;
 - import com.linpeng.fragment.FragmentQuestion;
 - import android.view.Menu;
 - import android.view.MenuItem;
 - import android.view.View;
 - import android.view.Window;
 - import android.app.Activity;
 - import android.app.Fragment;
 - import android.content.Intent;
 - import android.os.Bundle;
 - public class MainActivity extends Activity {
 - private Fragment[] fragments = new Fragment[4];
 - @Override
 - protected void onCreate(Bundle savedInstanceState) {
 - super.onCreate(savedInstanceState);
 - setContentView(R.layout.activity_main);
 - fragments[0] = new FragmentNews();
 - fragments[1] = new FragmentPostbar();
 - fragments[2] = new FragmentQuestion();
 - fragments[3] = new FragmentPhoto();
 - getFragmentManager().beginTransaction().add(R.id.main_fragment,fragments[1])
 - .add(R.id.main_fragment,fragments[2]).add(R.id.main_fragment,fragments[3]).add(R.id.main_fragment,fragments[0]).commit();
 - newsClick(null);
 - }
 - public void newsClick(View view){
 - getFragmentManager().beginTransaction().hide(fragments[1])
 - .hide(fragments[2]).hide(fragments[3]).show(fragments[0]).commit();
 - getActionBar().setTitle("新聞");
 - }
 - public void postbarClick(View view){
 - getFragmentManager().beginTransaction().hide(fragments[0])
 - .hide(fragments[2]).hide(fragments[3]).show(fragments[1]).commit();
 - getActionBar().setTitle("貼吧");
 - }
 - public void questionClick(View view){
 - getFragmentManager().beginTransaction().hide(fragments[0])
 - .hide(fragments[1]).hide(fragments[3]).show(fragments[2]).commit();
 - getActionBar().setTitle("知道");
 - }
 - public void photoClick(View view){
 - getFragmentManager().beginTransaction().hide(fragments[0])
 - .hide(fragments[1]).hide(fragments[2]).show(fragments[3]).commit();
 - getActionBar().setTitle("圖片");
 - }
 - @Override
 - public boolean onCreateOptionsMenu(Menu menu) {
 - getMenuInflater().inflate(R.menu.menu, menu);
 - return true;
 - }
 - @Override
 - public boolean onMenuItemSelected(int featureId, MenuItem item) {
 - switch (item.getItemId()) {
 - case R.id.menu_share:
 - Intent intent = new Intent(Intent.ACTION_SEND);
 - intent.setType("text/plain");
 - intent.putExtra(Intent.EXTRA_TEXT, "這是一個(gè)可以定制關(guān)鍵詞的新聞app,歡迎體驗(yàn)");
 - startActivity(Intent.createChooser(intent, getTitle()));
 - break;
 - default:
 - break;
 - }
 - return super.onMenuItemSelected(featureId, item);
 - }
 - @Override
 - public boolean onMenuOpened(int featureId, Menu menu) {
 - if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
 - if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
 - try {
 - Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
 - m.setAccessible(true);
 - m.invoke(menu, true);
 - } catch (Exception e) {
 - e.printStackTrace();
 - }
 - }
 - }
 - return super.onMenuOpened(featureId, menu);
 - }
 - }
 
責(zé)任編輯:倪明 
                    來源:
                    devstore
 















 
 
 






 
 
 
 