自己练习中收藏的一些重要的东西,记录一下方便使用。
Android去掉Button自带的阴影
style=”?android:attr/borderlessButtonStyle”
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />
Android设置Spinner控件的文字居中显示
android:textAlignment="center"
SimpleCursorAdapter中显示layout中的图片:
只需要将图片格式改为bmp
listViewAdapter = new SimpleCursorAdapter(this,
R.layout.item_list,
result,
new String[]{"payer","type", "date", "ps","money"},
new int[]{R.id.payershow,R.id.typeshow, R.id.dateshow2, R.id.psshow,R.id.moneyshow},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
//3.视图加载适配器
listView.setAdapter(listViewAdapter);
Android app 去除顶部蓝色导航栏(Action Bar)
http://t.csdn.cn/ZE0tghttp://t.csdn.cn/ZE0tg
实现RadioButton切换图片
final RadioButton five = findViewById(R.id.radio);//获取button
Drawable myImage = res.getDrawable(R.drawable.home);//获取资源图片
five.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);//四个属性分别代表drawleft drawtop...
实现从fragment 跳转到Activity
实现从fragment 跳转到Activityhttp://t.csdn.cn/ywRwZ
自定义字体
http://t.csdn.cn/XuEQChttp://t.csdn.cn/XuEQC
折腾了一晚上的保存fragment的状态,刚开始用的replace就不行,后面改成了用add和hide就可以了。我是先添加了所有的页面,然后再隐藏,通过按钮点击事件来显示具体的页面。所以为什么2022了,Android的fragment还是不能像activity一样自动保存状态呢?我不理解,就是给我增加难度。
group.setOnCheckedChangeListener(
new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
//设置按钮状态图片为点击前的样式
five.setCompoundDrawablesWithIntrinsicBounds(null, geren_grey,null,null);
//隐藏所有的页面
getSupportFragmentManager().beginTransaction()
.hide(first)
.commit();
getSupportFragmentManager().beginTransaction()
.hide(second)
.commit();
getSupportFragmentManager().beginTransaction()
.hide(third)
.commit();
getSupportFragmentManager().beginTransaction()
.hide(forth)
.commit();
getSupportFragmentManager().beginTransaction()
.hide(unlogin)
.commit();
if (one.isChecked()){
// 显示页面1
getSupportFragmentManager().beginTransaction()
.show(first)
.addToBackStack(null)
.commit();
}
else if (two.isChecked()){
getSupportFragmentManager().beginTransaction()
.show(second)
.addToBackStack(null)
.commit();
}
else if (three.isChecked()){
getSupportFragmentManager().beginTransaction()
.show(third)
.addToBackStack(null)
.commit();
}
else if (four.isChecked()){
getSupportFragmentManager().beginTransaction()
.show(forth)
.addToBackStack(null)
.commit();
}
else if (five.isChecked()){
five.setCompoundDrawablesWithIntrinsicBounds(null, geren_blue,null,null);
getSupportFragmentManager().beginTransaction()
.show(unlogin)
.addToBackStack(null)
.commit();
}
}
});
在指定Activity中隐藏顶部导航栏
ActionBar actionbar = getSupportActionBar();
actionbar.hide();
点击一个页面就要创建一个activity。感觉太多了,查找一下怎么解决。确实通过传递数据的方法可以解决,可以不用一个页面写一个activity。
如何在 Android 中为不同的内容使用相同的 Activity? https://qa.1r1g.com/sf/ask/2634882701/
【Android开发】intent.putExtra()方法参数详解及示例https://www.jianshu.com/p/8a9b84df5018
商品展示可以用RecyclerView和Cardview