android actionbar自定义View并添加点击事件
2017-09-05 14:45
573 查看
LoginActivity.java
vrepair_actionbar.xml文件
activity_login.xml没什么特别的
public class LoginActivity extends AppCompatActivity { public static final String TAG = "ZCN_LoginActivity"; private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { Log.d(TAG,"actionBar不为空"); View titleView = LayoutInflater.from(this).inflate(R.layout.vrepair_actionbar, new LinearLayout(this), false); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); //Enable自定义的View actionBar.setCustomView(titleView);//设置自定义的布局 iv = (ImageView)titleView.findViewById(R.id.iv_actionbar_back); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG,"=====请输出====="); } }); } } }
vrepair_actionbar.xml文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_actionbar_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:background="@mipmap/ic_launcher"/> <TextView android:id="@+id/tv_actionbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="aaaaa" android:layout_centerInParent="true" /> </RelativeLayout>
activity_login.xml没什么特别的
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" tools:context="com.sdlj.vehiclerepair.activity.LoginActivity"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="我是主界面,哈哈哈哈" android:textColor="@color/black"/> </LinearLayout>
相关文章推荐
- Android自定义View与添加点击事件
- Android TextView 给文本中指定片段添加自定义点击事件
- Android中Recyclerview使用6----添加条目得到点击事件和长按事件(另一种写法,较简单)
- 关于android自定义切割view并在每个区域设置点击事件
- Android中为RecyclerView添加item的点击事件
- Android TextView 高亮字体并添加点击事件
- 为UIImageView添加点击事件,隐藏UINavigationBar和UITabViewControllerBar
- Android TextView加载HTMl图文之添加点击事件和查看图片
- 自定义View添加点击事件
- Android开发给TextView添加点击事件
- Android 自定义view模板,并实现点击事件的回调
- Android中RecyclerView添加item的点击事件
- 0917Android基础自定义View的点击事件
- Android自定义View中的常用方法(距离、位置、点击事件)
- Android给TextView添加点击事件的实现方法
- android 7.0 切换语言界面切换语言后点击“添加语言”的加号进入语言选择列表不做任何操作返回返现actionbar标题异常
- Android 给TextView添加点击事件
- Android TextView 高亮字体并添加点击事件
- Android 给TextView添加点击事件
- Android 自定义View——自定义点击事件