App的设计思路(持续更新)
一、如何创建新的Activity继承使用BaseActivity的布局功能并独立定义自己的布局设计思路
例如BaseActivity中设置了一个activity_base.xml,使用了setContentView(R.layout.activity_base),这时我们并不能直接继承后使用自己的setContentView方法,需要这么处理
1.新建一个activity_base.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/layout_toolbar"/> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> <!--加载失败--> <ViewStub android:id="@+id/vs_error_refresh" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout="@layout/layout_loading_error" /> <!--加载中..--> <ViewStub android:id="@+id/vs_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout="@layout/layout_loading_view" /> </FrameLayout> </LinearLayout>
2.新建一个BaseActivity.java
public abstract class BaseActivity extends AppCompatActivity { /** * 获取继承的Activity的显示view的xml文件ID */ protected abstract int getContentViewId(); @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_base) //将继承Activity的布局添加到activity_base.xml中的container布局中 ViewGroup container = (ViewGroup) LayoutInflater.from(this).inflate(getContentViewId(), findViewById(R.id.container)); } }
3.若创建一个新的Activity的话只需要继承BaseActivity,并实现了布局复用和独立的layout办法
二、自定义EditText中设置drawableRight,然后获取。
1.xml中设置drawableRight中
<com.mdm.widget.ClearEditText android:drawableRight="@drawable/add" android:id="@+id/et_room1_name" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginStart="@dimen/dimen_16" android:background="@null" android:gravity="center_vertical" android:hint="入住人真实姓名" android:includeFontPadding="false" android:inputType="text" android:textColor="#ff272a2b" android:textColorHint="#ffa9adad" android:textSize="@dimen/sp_14" android:layout_marginTop="@dimen/dimen_14" android:layout_marginEnd="16dp" />
2.ClearEditText中获取设置
// 获取EditText的DrawableRight,假如没有设置我们就使用默认的图片 mClearDrawable = getCompoundDrawables()[2];
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效