Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。



4
在CoordinatorLayout的工具栏下方添加视图
我有以下布局: <android.support.design.widget.CoordinatorLayout android:id="@+id/main_content" 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.support.design.widget.AppBarLayout android:id="@+id/appBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.design.widget.CoordinatorLayout> 我将Fragments 添加到中FrameLayout,替换它们。我Fragment的其中一个是列表,其布局如下: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 我的问题是在列表上方绘制了工具栏。我试图通过包装的内容,以解决CoordinatorLayout成LinearLayout,即解决了透支,但这样的appbar滚动行为不再起作用。 任何帮助深表感谢!




1
获取当前的片段对象
在我main.xml我有 <FrameLayout android:id="@+id/frameTitle" android:padding="5dp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="@drawable/title_bg"> <fragment android:name="com.fragment.TitleFragment" android:id="@+id/fragmentTag" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </FrameLayout> 我像这样设置片段对象 FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment newFragment = new FragmentType1(); fragmentTransaction.replace(R.id.frameTitle, casinodetailFragment, "fragmentTag"); // fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); 它FragmentType2,FragmentType3,...在不同的时间设置不同类型的Fragment对象()。现在在某个时间点,我需要确定当前存在哪个对象。 在短,我需要做这样的事情: Fragment currentFragment = //what is the way to get current fragment object in FrameLayout …


7
NavigationView获取/查找标题布局
在我的NavigationView中,我有一个带有活动按钮的ID为'viewId'的标题布局。要设置这些按钮,我将在活动中执行以下操作onPostCreate: final View panel = findViewById(R.id.viewId); panel.setOnClickListener(new View.OnClickListener() { ... setup goes here ... }); 使用新版本的android支持库(23.1.0),找不到视图,它返回null。使用以前的版本,效果很好。是错误还是我使用此功能有误?如果是这样,如何访问标题布局并为其添加行为?


18
自定义字体和XML布局(Android)
我正在尝试使用Android中的XML文件定义GUI布局。据我所知,没有办法指定您的窗口小部件应在XML文件中使用一种自定义字体(例如,您放置在Assets / font /中的字体),并且只能使用系统安装的字体。 我知道,在Java代码中,我可以使用唯一ID手动更改每个小部件的字体。另外,我可以遍历Java中的所有小部件以进行此更改,但这可能会很慢。 我还有什么其他选择?有没有更好的方法来制作具有自定义外观的小部件?我特别不想为添加的每个新小部件手动更改字体。


18
将重点放在EditText上
我有一个EditText-Field并为其设置了OnFocusChangeListener。当失去焦点时,将调用一个方法,该方法将在数据库中检查EditText的值。如果该方法的返回值是true,则显示一个敬酒,焦点应再次回到EditText上。焦点应该总是回到EditText上,并且键盘应该显示出来,直到该方法的返回值为false为止。 编辑:我想,我还没有完全弄清我真正的问题:屏幕上的其他任何项目都不能编辑,直到EditText的值被编辑为一个值,这使得方法“ checkLiganame(liganame) ”返回假。只有EditText-Field应该可以编辑。 这是我的代码(不适用于我): final EditText Liganame = (EditText) findViewById(R.id.liganame); Liganame.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { String liganame = Liganame.getText().toString(); if (checkLiganame(liganame)) { Toast toast = Toast.makeText(CreateTableActivity.this, "Dieser Liganame ist bereits vergeben", Toast.LENGTH_SHORT); toast.show(); Liganame.requestFocus(); } } 和方法: public boolean checkLiganame(String …



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.