80,351
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#EBEBEB">
<LinearLayout
android:id="@+id/left_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
>
<ImageView
android:id="@+id/left_msg_imageView"
android:layout_width="30dp"
android:layout_height="match_parent"
android:src="@drawable/g1"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_left">
<TextView
android:id="@+id/left_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="6dp"
android:textColor="#505050"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/right_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/message_right">
<TextView
android:id="@+id/right_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:textColor="#505050"/>
</LinearLayout>
<ImageView
android:id="@+id/right_msg_imageView"
android:layout_width="30dp"
android:layout_height="match_parent"
android:src="@drawable/g2"
/>
</LinearLayout>
</LinearLayout>
package com.example.wangchang.testbottomnavigationbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener {
private ArrayList<Fragment> fragments;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
bottomNavigationBar
.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
bottomNavigationBar.addItem(new BottomNavigationItem(R.mipmap.ic_home_white_24dp, "首页").setActiveColorResource(R.color.orange))
.addItem(new BottomNavigationItem(R.mipmap.ic_music_note_white_24dp, "活动").setActiveColorResource(R.color.blue))
.addItem(new BottomNavigationItem(R.mipmap.ic_book_white_24dp, "咨询").setActiveColorResource(R.color.teal))
.addItem(new BottomNavigationItem(R.mipmap.ic_tv_white_24dp, "我").setActiveColorResource(R.color.brown))
.setFirstSelectedPosition(0)
.initialise();
fragments = getFragments();
setDefaultFragment();
bottomNavigationBar.setTabSelectedListener(this);
}
/**
* 设置默认的
*/
private void setDefaultFragment() {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.layFrame, RecommendationFragment.newInstance("首页"));
transaction.commit();
}
private ArrayList<Fragment> getFragments() {
ArrayList<Fragment> fragments = new ArrayList<>();
fragments.add(RecommendationFragment.newInstance("首页"));
fragments.add(ActivityFragment.newInstance("活动"));
fragments.add(ConsultFragment.newInstance("咨询"));
fragments.add(AboutFragment.newInstance("我"));
return fragments;
}
@Override
public void onTabSelected(int position) {
if (fragments != null) {
if (position < fragments.size()) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = fragments.get(position);
if (fragment.isAdded()) {
ft.add(R.id.layFrame, fragment);
} else {
ft.replace(R.id.layFrame, fragment);
}
ft.commitAllowingStateLoss();
}
}
}
@Override
public void onTabUnselected(int position) {
if (fragments != null) {
if (position < fragments.size()) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = fragments.get(position);
ft.remove(fragment);
ft.commitAllowingStateLoss();
}
}
}
@Override
public void onTabReselected(int position) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/im_messagelist_back"
android:layout_height="48dp" android:paddingLeft="72dp"
android:paddingRight="16dp" android:minHeight="48dp">
<my.CircleImageView android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/ib_user_default"
android:id="@+id/imageView"
android:layout_marginTop="4dp" android:layout_alignParentRight="true"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello"
android:background="@drawable/ib_bubble_right" android:textColor="#000" android:minHeight="40dp"
android:layout_toLeftOf="@+id/imageView" android:layout_centerVertical="true"
android:layout_marginRight="4dp" android:textSize="14sp" android:gravity="center|left" android:id="@+id/tv_SubTitle"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:background="@drawable/im_messagelist_back"
android:layout_height="48dp" android:paddingLeft="16dp" android:paddingRight="72dp" android:minHeight="48dp">
<my.CircleImageView android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/ib_user_default"
android:id="@+id/imageView" android:layout_marginTop="4dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello"
android:layout_toRightOf="@+id/imageView" android:layout_centerVertical="true"
android:layout_marginLeft="4dp" android:background="@drawable/ib_bubble_left" android:textColor="#fff" android:minHeight="40dp"
android:textSize="14sp" android:id="@+id/tv_SubTitle" android:gravity="left|center"/>
</RelativeLayout>