PS:使用design包需要在design项目中导入appcompat包
使用到的控件包括:
CoordinatorLayout
AppBarLayout—–>
AppBarLayout.OnOffsetChangedListener的使用
CollapsingToolbarLayout
Toolbar
RecyclerView
CardView—–>
关于使用 CardView 开发过程中要注意的细节
FloatingActionButton
Snackbar—–>
从顶部显示的snackbar
基本结构:
import java.util.Arrays;
import com.mb.widget.Cheeses;
import com.mb.widget.SimpleStringRecyclerViewAdapter;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
/**
* http://www.open-open.com/lib/view/open1437312265428.html
* @author pythoner
*
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// App Logo
// toolbar.setLogo(R.drawable.ic_launcher);
// Title
toolbar.setTitle("App Title");
// Sub Title
toolbar.setSubtitle("Sub title");
//Navigation Icon
toolbar.setNavigationIcon(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
//通常,我们我们都是设置Toolbar的title,而现在,我们需要把title设置在CollapsingToolBarLayout上,而不是Toolbar。
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setTitle("Title");
FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.floatingActionButton);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Snackbar snackbar = Snackbar.make(coordinatorLayout, "测试弹出提示", Snackbar.LENGTH_LONG);
snackbar.show();
snackbar.setAction("取消", new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
}
});
}
});
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this,Arrays.asList(Cheeses.sCheeseStrings)));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
@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);
}
}
参考:
http://www.open-open.com/lib/view/open1437312265428.html
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0718/3197.html
http://www.jcodecraeer.com/a/anzhuokaifa/developer/2015/0531/2958.html
android design library提供的TabLayout的用法
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0731/3247.html
当InstaMaterial遇到Design Support Library
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0728/3224.html
总结一下现在关于Design Support Library的几个博客
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0713/3179.html
TabbedCoordinatorLayout是一个演示在CollapsingToolbarLayout中使用TabLayout的例子,两者均放在CoordinatorLayout中
http://www.jcodecraeer.com/a/opensource/2015/1010/3564.html
新的AppBarLayout flag:SCROLL_FLAG_SNAP
http://www.open-open.com/lib/view/open1445225861898.html
- Test.rar (9.6 MB)
- 描述: 需要android5.1.1编译
- 下载次数: 4
- 大小: 1.7 MB
- 大小: 863.3 KB
- 大小: 2.5 MB
- 查看图片附件
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net