Browse Source

框架搭建配色

developer
lh 8 years ago
parent
commit
1e48fa578a
11 changed files with 235 additions and 40 deletions
  1. +179
    -10
      app/src/main/java/com/qhclh/ytzh/home/MainActivity.java
  2. +13
    -6
      app/src/main/res/layout/act_main.xml
  3. +1
    -0
      app/src/main/res/layout/fragment_index.xml
  4. +3
    -1
      app/src/main/res/layout/fragment_me.xml
  5. +3
    -1
      app/src/main/res/layout/fragment_work.xml
  6. +1
    -1
      app/src/main/res/layout/include_line.xml
  7. +18
    -12
      app/src/main/res/layout/include_tab_bar.xml
  8. +8
    -4
      app/src/main/res/values/colors.xml
  9. +3
    -3
      app/src/main/res/values/dimens.xml
  10. +5
    -1
      app/src/main/res/values/strings.xml
  11. +1
    -1
      app/src/main/res/values/styles.xml

+ 179
- 10
app/src/main/java/com/qhclh/ytzh/home/MainActivity.java View File

@ -1,20 +1,54 @@
package com.qhclh.ytzh.home;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseActivity;
import com.qhclh.ytzh.index.IndexFragment;
import com.qhclh.ytzh.me.MeFragment;
import com.qhclh.ytzh.work.WorkFragment;
import butterknife.BindView;
import butterknife.OnClick;
public class MainActivity extends BaseActivity {
@BindView(R.id.textaaa)
TextView textView;
@BindView(R.id.toolbar)
Toolbar mToolbar;
@BindView(R.id.tv_toolbar_title)
TextView mTvToolbarTitle;
@BindView(R.id.iv_index)
ImageView iv_index;
@BindView(R.id.tv_index)
TextView tv_index;
@BindView(R.id.iv_work)
ImageView iv_work;
@BindView(R.id.tv_work)
TextView tv_work;
@BindView(R.id.iv_me)
ImageView iv_me;
@BindView(R.id.tv_me)
TextView tv_me;
private long mLastClickTime;
private static final long DEFAULT_EXIT_TIME = 2000;
///< 首页
private static final int TAB_POSITION_INDEX = 0;
///< 工作
private static final int TAB_POSITION_WORK = 1;
///< 我的
private static final int TAB_POSITION_ME = 2;
private int mCurrentTabPosition = -1;
private int mTargetTabPosition = TAB_POSITION_INDEX;
private IndexFragment indexFragment;
private WorkFragment workFragment;
private MeFragment meFragment;
@Override
protected int setLayoutId() {
@ -23,21 +57,156 @@ public class MainActivity extends BaseActivity {
@Override
protected void initView() {
initToolbar(mToolbar, "aaaaa", new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
initToolbar(mToolbar, "", null);
///< 点击切换fragment
onTabClick(mTargetTabPosition);
}
@Override
protected void initData() {
textView.setText("aaaaaaaaaaa");
}
@Override
protected void initOper() {
}
@OnClick({R.id.ll_index, R.id.ll_work, R.id.ll_me})
public void onClick(View view) {
switch (view.getId()) {
///< 首页
case R.id.ll_index: {
onTabClick(TAB_POSITION_INDEX);
break;
}
///< 工作
case R.id.ll_work: {
onTabClick(TAB_POSITION_WORK);
break;
}
///< 我的
case R.id.ll_me: {
onTabClick(TAB_POSITION_ME);
break;
}
}
}
private void onTabClick(int tabPosition) {
if (mCurrentTabPosition == tabPosition) {
return;
}
mCurrentTabPosition = tabPosition;
changeTabState(tabPosition);
changeFragment(tabPosition);
}
private void changeTabState(int tabPosition) {
clearAllTabState();
switch (tabPosition) {
case TAB_POSITION_INDEX: {
// iv_index.setImageResource(R.drawable.ghs12x);
tv_index.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.index);
break;
}
case TAB_POSITION_WORK: {
// iv_work.setImageResource(R.drawable.gwc12x);
tv_work.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.work);
break;
}
case TAB_POSITION_ME: {
// iv_me.setImageResource(R.drawable.dd12x);
tv_me.setTextColor(getResources().getColor(R.color.green029737));
mTvToolbarTitle.setText(R.string.me);
break;
}
}
}
private void clearAllTabState() {
///< 首页
// iv_index.setImageResource(R.drawable.ghs2x);
tv_index.setTextColor(getResources().getColor(R.color.grey888888));
///< 工作
// iv_work.setImageResource(R.drawable.gwc2x);
tv_work.setTextColor(getResources().getColor(R.color.grey888888));
///< 我的
// iv_me.setImageResource(R.drawable.dd2x);
tv_me.setTextColor(getResources().getColor(R.color.grey888888));
}
private void changeFragment(int tabPosition) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
hideFragment(transaction);
switch (tabPosition) {
case TAB_POSITION_INDEX: {
if (indexFragment == null) {
indexFragment = new IndexFragment();
transaction.add(R.id.main_container, indexFragment);
} else {
transaction.show(indexFragment);
}
break;
}
case TAB_POSITION_WORK: {
if (workFragment == null) {
workFragment = new WorkFragment();
transaction.add(R.id.main_container, workFragment);
} else {
transaction.show(workFragment);
}
break;
}
case TAB_POSITION_ME: {
if (meFragment == null) {
meFragment = new MeFragment();
transaction.add(R.id.main_container, meFragment);
} else {
transaction.show(meFragment);
}
break;
}
}
transaction.commitAllowingStateLoss();
}
private void hideFragment(FragmentTransaction transaction) {
if (indexFragment != null) {
transaction.hide(indexFragment);
}
if (workFragment != null) {
transaction.hide(workFragment);
}
if (meFragment != null) {
transaction.hide(meFragment);
}
}
@Override
public void onBackPressed() {
// super.onBackPressed();
exitApp();
}
///< back键退出
private void exitApp() {
long currentTime = System.currentTimeMillis();
if (currentTime - mLastClickTime < DEFAULT_EXIT_TIME) {
finishAll();
} else {
mLastClickTime = currentTime;
showToast(getString(R.string.back_exit_app));
}
}
}

+ 13
- 6
app/src/main/res/layout/act_main.xml View File

@ -1,12 +1,19 @@
<?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:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/include_tool_bar"></include>
<TextView
android:id="@+id/textaaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<include layout="@layout/include_line"></include>
<include layout="@layout/include_tab_bar"></include>
</LinearLayout>

+ 1
- 0
app/src/main/res/layout/fragment_index.xml View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/greyf4f4f4"
android:layout_height="match_parent">
<TextView
android:text="@string/index"


+ 3
- 1
app/src/main/res/layout/fragment_me.xml View File

@ -1,6 +1,8 @@
<?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:orientation="vertical"
android:background="@color/greyf4f4f4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/me"


+ 3
- 1
app/src/main/res/layout/fragment_work.xml View File

@ -1,6 +1,8 @@
<?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:orientation="vertical"
android:background="@color/greyf4f4f4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/work"


+ 1
- 1
app/src/main/res/layout/include_line.xml View File

@ -2,5 +2,5 @@
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/grey_a3a3a3">
android:background="@color/greydbdbdb">
</View>

+ 18
- 12
app/src/main/res/layout/include_tab_bar.xml View File

@ -7,39 +7,45 @@
android:orientation="horizontal">
<!-- 底部导航栏-->
<LinearLayout
android:id="@+id/ll_gonghuoshang"
android:id="@+id/ll_index"
style="@style/TabLayout">
<ImageView
android:id="@+id/iv_gonghuoshang"
android:id="@+id/iv_index"
style="@style/TabIcon" />
<TextView
android:id="@+id/tv_gonghuoshang"
android:id="@+id/tv_index"
style="@style/TabText"
android:text="@string/app_name" />
android:text="@string/index" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_gouwuche"
android:id="@+id/ll_work"
style="@style/TabLayout">
<ImageView
android:id="@+id/iv_gouwuche"
android:id="@+id/iv_work"
style="@style/TabIcon" />
<TextView
android:id="@+id/tv_gouwuche"
android:id="@+id/tv_work"
style="@style/TabText"
android:text="@string/app_name" />
android:text="@string/work" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_dingdan"
android:id="@+id/ll_me"
style="@style/TabLayout">
<ImageView
android:id="@+id/iv_dingdan"
android:id="@+id/iv_me"
style="@style/TabIcon" />
<TextView
android:id="@+id/tv_dingdan"
android:id="@+id/tv_me"
style="@style/TabText"
android:text="@string/app_name" />
android:text="@string/me" />
</LinearLayout>
</LinearLayout>

+ 8
- 4
app/src/main/res/values/colors.xml View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--标题栏 -->
<color name="colorPrimary">#E3383B</color>
<color name="colorPrimary">#0b9343</color>
<!-- 状态栏-->
<color name="colorPrimaryDark">#E3383B</color>
<color name="colorPrimaryDark">#0b9343</color>
<!-- 各种控件默认选中颜色-->
<color name="colorAccent">#E3383B</color>
<color name="colorAccent">#0b9343</color>
<color name="grey999">#999999</color>
@ -15,10 +15,14 @@
<color name="red_ee">#eeee4242</color>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="grey_767c82">#767c82</color>
<color name="grey_767c82">#888888</color>
<color name="black_282828">#282828</color>
<color name="tran">#00000000</color>
<color name="grey_a3a3a3">#a3a3a3</color>
<color name="green029737">#029737</color>
<color name="grey888888">#888888</color>
<color name="greyf4f4f4">#f4f4f4</color>
<color name="greydbdbdb">#dbdbdb</color>
</resources>

+ 3
- 3
app/src/main/res/values/dimens.xml View File

@ -131,9 +131,9 @@
<dimen name="px_8">8px</dimen>
<dimen name="px_20">20px</dimen>
<dimen name="tab_text_size">@dimen/text_size_12</dimen>
<dimen name="tab_icon_height">24dp</dimen>
<dimen name="tab_icon_width">24dp</dimen>
<dimen name="tab_text_size">@dimen/text_size_16</dimen>
<dimen name="tab_icon_height">30dp</dimen>
<dimen name="tab_icon_width">30dp</dimen>
<dimen name="tab_layout_padding">8dp</dimen>
<!-- ************************************************************分割线************************************************************-->


+ 5
- 1
app/src/main/res/values/strings.xml View File

@ -1,3 +1,7 @@
<resources>
<string name="app_name">Ytzh</string>
<string name="app_name">亚太中慧</string>
<string name="index">首页</string>
<string name="work">工作</string>
<string name="me">我的</string>
<string name="back_exit_app">再按一次返回键退出应用</string>
</resources>

+ 1
- 1
app/src/main/res/values/styles.xml View File

@ -28,7 +28,7 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">@dimen/text_size_18</item>
<item name="android:textSize">@dimen/text_size_20</item>
</style>
<style name="TabLayout">


Loading…
Cancel
Save