-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
800 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
package com.wakehao.demo; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
|
||
import com.wakehao.bar.BottomNavigationBar; | ||
import com.wakehao.bar.BottomNavigationItem; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
BottomNavigationBar bar= (BottomNavigationBar) findViewById(R.id.bar); | ||
|
||
// bar.setOnNavigationItemSelectedListener(new BottomNavigationBar.OnNavigationItemSelectedListener() { | ||
// @Override | ||
// public boolean onNavigationItemSelected(@NonNull BottomNavigationItem item, int selectedPosition) { | ||
// return selectedPosition==2?false:true; | ||
// } | ||
// }); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
bottom-navigation-bar/src/main/java/com/wakehao/bar/BarUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.wakehao.bar; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffColorFilter; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Created by WakeHao on 2017/1/10. | ||
*/ | ||
|
||
public class BarUtils { | ||
/** | ||
* 根据手机的分辨率从dp的单位转成为px(像素) | ||
*/ | ||
public static int dip2px(Context context, float dpValue){ | ||
|
||
final float scale=context.getResources().getDisplayMetrics().density; | ||
|
||
return (int)(dpValue*scale+0.5f); | ||
|
||
} | ||
|
||
/** | ||
* 根据手机的分辨率从px(像素)的单位转成为dp | ||
*/ | ||
public static int px2dip(Context context,float pxValue) { | ||
|
||
final float scale=context.getResources().getDisplayMetrics().density; | ||
|
||
return (int)(pxValue/scale+0.5f); | ||
|
||
} | ||
|
||
public static float px2sp(@NotNull Context context, float pxValue) { | ||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | ||
return (int) (pxValue / fontScale); | ||
} | ||
|
||
public static float sp2px(@NotNull Context context, float spValue) { | ||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | ||
return (spValue * fontScale); | ||
} | ||
|
||
public static Drawable changeDrawableColor(int drawableRes, int colorRes, Context context) { | ||
//Convert drawable res to bitmap | ||
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableRes); | ||
final Bitmap resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, | ||
bitmap.getWidth() - 1, bitmap.getHeight() - 1); | ||
final Paint p = new Paint(); | ||
final Canvas canvas = new Canvas(resultBitmap); | ||
canvas.drawBitmap(resultBitmap, 0, 0, p); | ||
|
||
//Create new drawable based on bitmap | ||
final Drawable drawable = new BitmapDrawable(context.getResources(), resultBitmap); | ||
drawable.setColorFilter(new | ||
PorterDuffColorFilter(colorRes, PorterDuff.Mode.MULTIPLY)); | ||
return drawable; | ||
} | ||
public static int getDeviceWidth(Context context) | ||
{ | ||
return context.getResources().getDisplayMetrics().widthPixels; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.