我试图将所有图标居中,我已经使用以下代码禁用了移位模式:
/**
* This is done to remove the shift animation introduced by Android on the bottom navigation view
* /sf/answers/2918332301/
*/
@SuppressLint("RestrictedApi")
public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
//noinspection RestrictedApi
item.setShiftingMode(false);
item.setPadding(0,15,0,0);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
} …Run Code Online (Sandbox Code Playgroud) 这是我的build.gradle档案:
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:21.0.+'
...
}
Run Code Online (Sandbox Code Playgroud)
在我添加之前:
compile 'com.android.support:design:22.2.0'
Run Code Online (Sandbox Code Playgroud)
现在当我构建或重建我的项目时(我已经同步gradle了几次)我得到了这个错误:
.../utils/CustomEditText.java
Error:(6, 42) Gradle: error: cannot find symbol class TintEditText
Error:(14, 35) Gradle: error: cannot find symbol class TintEditText
Error:(37, 8) Gradle: error: cannot find symbol method isInEditMode()
Error:(57, 3) Gradle: error: cannot find symbol method setTypeface(Typeface)
Error:(65, 5) Gradle: error: method does not override or implement a method from a supertype
Error:(67, 23) Gradle: error: cannot …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-gradle-plugin android-support-design
我正在尝试使用Eclipse创建基于Google"材料设计"的菜单选项卡,但是我收到了一个错误:
01-07 01:02:10.238: E/tag(6696): contact on create called
01-07 01:02:10.301: E/AndroidRuntime(6696): FATAL EXCEPTION: main
01-07 01:02:10.301: E/AndroidRuntime(6696): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rvappsstudios.designflashalerts/com.rvappsstudios.designflashalerts.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rvappsstudios.designflashalerts/com.rvappsstudios.designflashalerts.Contact_mainfragment}: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.design.widget.TabLayout
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.app.ActivityThread.access$600(ActivityThread.java:162)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.os.Handler.dispatchMessage(Handler.java:107)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.os.Looper.loop(Looper.java:194)
01-07 01:02:10.301: E/AndroidRuntime(6696): at android.app.ActivityThread.main(ActivityThread.java:5371)
01-07 01:02:10.301: E/AndroidRuntime(6696): at java.lang.reflect.Method.invokeNative(Native Method) …Run Code Online (Sandbox Code Playgroud) 我建立了一个基于Scrolling Activity(由android studio建议的预建活动)的项目,并面临一个奇怪的问题.请考虑以下情形:
我点击fab按钮转到另一个fragment但是当片段改变时,fab按钮不会消失!
谁能知道如何解决这个问题?
这是我Scrolling Activity添加到我的XML frameLayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ir.apio.myapplication.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scrolling" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end" />
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
content_scrolling.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-fragments material-design floating-action-button android-support-design
所以我有一个应用程序,用户可以通过选择一组颜色来选择颜色RadioButtons,我已经使用ButtonTintXML属性为按钮着色,但显然这仅适用于API > 21/.
所以我的问题是,
如何更改RadioButtonsKitKat(API 19)及以下的颜色?
我已经从其他堆栈溢出问题中测试了一些方法,但到目前为止还没有一个有效.
xml android android-support-library android-studio android-support-design
我有NavigationView多个组,这是基于我需要隐藏和显示组的一些条件.我怎么能做到这一点.
我的示例NavigationView菜单
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"
android:id="@+id/grp_employee"
>
<item
android:id="@+id/help"
android:checked="false"
android:icon="@drawable/ic_help"
android:title="@string/app_name" />
.......
</group>
<group android:checkableBehavior="single"
android:id="@+id/grp_admin"
>
<item
android:id="@+id/admin_help"
android:checked="false"
android:icon="@drawable/ic_help"
android:title="@string/app_name" />
.......
</group>
<group> ... </group>
</menu>
Run Code Online (Sandbox Code Playgroud)
这是我的NavigationView文件.我只想一次只显示一个组视图隐藏所有其他组.
android navigationview android-support-design android-navigationview
我在我的一个应用布局中使用TextInputLayout.我的应用程序在Lollipop(5.1)及更高版本的用户设备上崩溃.以下是错误
android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by java.lang.reflect.InvocationTargetException: arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/design_password_eye.xml from drawable resource ID #0x7f0200b1 arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password.xml from drawable resource ID #0x7f02005c arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password_1.xml from …Run Code Online (Sandbox Code Playgroud) android android-layout android-support-library android-support-design android-textinputlayout
我在每个支持设计小部件上都出错。像recyclerview,协调器布局等。每次,我添加一个正在显示的支持设计小部件。
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
Run Code Online (Sandbox Code Playgroud)
在布局问题部分。我正在使用api 28.0.0-rc01,gradle 4.4 android 3.1.4。这是我的build.gradle(app)文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.android.test5test"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.2'
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:cardview-v7:28.0.0-rc01'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
}
Run Code Online (Sandbox Code Playgroud)
这是我的布局文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android classnotfoundexception android-support-library android-support-design android-9.0-pie
我正在使用android支持设计小部件BottomNavigationView来制作我的底部导航项。这是工作的结果:

它有2个问题,第一个问题是没有在项目下显示标题,第二个问题是我要填充项目,我不想在导航上有可用空间,我只想让它们填充空间并在项目之间划分空间。
这是我的菜单代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_item1"
android:icon="@drawable/phone"
app:showAsAction="ifRoom"
android:title="??????" />
<item
android:id="@+id/action_item2"
android:icon="@mipmap/ic_history"
app:showAsAction="ifRoom"
android:title="????? ????" />
<item
android:id="@+id/action_item3"
android:icon="@drawable/sabad"
app:showAsAction="ifRoom"
android:title="??? ????" />
<item
android:id="@+id/action_item4"
android:icon="@drawable/market2"
app:showAsAction="ifRoom"
android:title="???????" />
</menu>
Run Code Online (Sandbox Code Playgroud)
这是xml代码:
` <RelativeLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.truiton.bottomnavigation.MainActivity">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:animateLayoutChanges="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemIconTint="#fff"
app:itemTextColor="#F2F2F4"
app:menu="@menu/bottom_navigation_items"/>
</RelativeLayout>`
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
android android-support-library android-support-design android-bottomnav
我在设计支持库中的BottomNavigationView遇到问题。我在activity_main.xml中使用它:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
app:itemIconSize="16dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="@color/white"
app:itemIconTint="@color/white"
app:itemBackground="@color/medium_purple"
app:menu="@menu/main"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
膨胀该xml时,应用程序崩溃。异常的完整堆栈跟踪如下:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.frolo.musp.dev/com.alexfrolov.mp.main.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:822)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line …Run Code Online (Sandbox Code Playgroud) android android-support-library android-support-design bottomnavigationview