项目小结

1.fragment的缓存

mViewPager.setOffscreenPageLimit(2);//多缓存一个页面

2.浮动按钮

      <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">
        </android.support.v7.widget.Toolbar>
3.Snackbar的使用,对比toast

Snackbar.make(view, “Replace with your own action”, Snackbar.LENGTH_LONG)
.setAction(“Action”, null).show();

4.设置窗体样式

//设置窗体无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//设置全屏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

5. Logger的通用方式

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Wombat {

final static Logger logger = LoggerFactory.getLogger(Wombat.class);
Integer t;
Integer oldT;

public void setTemperature(Integer temperature) {
oldT = t;
t = temperature;
logger.debug(“Temperature set to {}. Old temperature was {}.”, t, oldT);
if(temperature.intValue() > 50) {
logger.info(“Temperature has risen above 50 degrees.”);
}
}
}


6.webview加载返回json数据
private void parseJson(String responseString) {
        Gson gson = new Gson();
        mContext = gson.fromJson(responseString, Content.class);
        final ImageLoader imageloader = ImageLoader.getInstance();
        DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).build();
        imageloader.displayImage(mContext.getImage(), iv, options);
        String css = "<link rel=\"stylesheet\" href=\"file:///android_asset/css/news.css\" type=\"text/css\">";
        String html = "<html><head>" + css + "</head><body>" + mContext.getBody() + "</body></html>";
        html = html.replace("<div class=\"img-place-holder\">", "");
        mWebView.loadDataWithBaseURL("x-data://base", html, "text/html", "UTF-8", null);
    }

你可能感兴趣的:(android)