我想应用一些风格DatePicker.在平台中,attrs.xml我们可以看到以下属性DatePicker:
<declare-styleable name="DatePicker">
...
<!-- The text color for the selected date header text, ex. "2014" or
"Tue, Mar 18". This should be a color state list where the
activated state will be used when the year picker or day picker is
active.-->
<attr name="headerTextColor" format="color" />
<!-- The background for the selected date header. -->
<attr name="headerBackground" />
...
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
虽然我可以参考android:headerBackground,但出乎意料的是我无法为android:headerTextColor属性做到这一点.所以遵循以下代码styles.xml:
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.DatePicker">
<item name="android:headerBackground">@color/red</item> …Run Code Online (Sandbox Code Playgroud) android datepicker android-resources android-styles android-attributes
我试图通过使用对象动画师将视图缩放到布局大小.这是一个观点LinearLayout.视图确实拉伸,但直到两个方向(即X和Y)的屏幕尺寸.
这是代码.
我觉得问题是这个:
计算必须完成多少缩放的公式.
zoomTillX = screen_width/zoomView_width;
zoomTillY = screen_height/zoomView_height;
Run Code Online (Sandbox Code Playgroud)或者使用以错误方式完成的Animation属性代码.
请让我知道如何实现放大.
public class MainActivity extends AppCompatActivity {
TextView tv;
double screen_height;
LinearLayout zoomView;
double screen_width;
double zoomTillX;
double zoomTillY;
double zoomView_width;
double zoomView_height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
zoomView = (LinearLayout) findViewById(R.id.zoomView);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screen_height = (double)dm.heightPixels;
screen_width = (double)dm.widthPixels;
zoomView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
zoomView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
zoomView_width = (double)zoomView.getMeasuredWidth();
zoomView_height = (double)zoomView.getMeasuredHeight();
} …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它有一个在单独的进程中运行的远程服务:
<service android:name=".MyService" android:process=":remote"/>
Run Code Online (Sandbox Code Playgroud)
我也在使用 Application 类:
<application android:label="@string/app_name" android:name=".MyApplication" ...
Run Code Online (Sandbox Code Playgroud)
我可以做这样的事情吗?
public class MyApplication extends Application {
public MyApplication() {
if (isRemoteService()) {
setupLog("remoteservice.log");
} else {
setupLog("application.log");
}
}
Run Code Online (Sandbox Code Playgroud)
我想我可以获取进程名称并使用它来检测我是否在远程服务或主应用程序中,但我还没有找到如何获取进程名称。我可以从 获取 PID android.os.Process.myPID(),但这对我没有多大帮助。
我在Android Studio中链接了两个项目/模块.其中一个充当Api/Core,我需要某些类只能从这个模块访问,但可以从它的所有包中访问(因此在这种情况下"默认"是无用的).
但似乎在Java中它不是像内部(c#,swift)那样的修饰符."模块"修饰符是为Java 7提出的,但它没有实现.
那么,是否有任何方法可以保护模块的类与外界不同,而不会将其范围限制在当前的包中?
谢谢!
我正在尝试在材料设计中实现一个简单的导航抽屉,因此我的抽屉顶部有一个标题和一些文本项(A:CompactHeader Drawer,...)(见图1).单击标题图像时,应打开一个列表(B:mikepenz@gmail.com,...)并"覆盖"我现有的文本项(A)(见图2).如果选择了文本项(B),则原始列表(A)应该返回其原始位置,并且(B)不再可见(参见图1).

注意:这些截图来自教程,但代码太混乱了.我正在寻找一个相对简单的解决方案......我在想Fragments,但我不知道这是否是解决这个问题的正确方法.
android navigation-drawer material-design navigationview android-navigationview
我有一个RecyclerView。在适配器中,我有一个布尔标志来确定应为所有项目使用哪种布局:
public class MyAdapter extends RecyclerView.Adapter<MyHolder> {
private boolean mIsSecondModeEnabled;
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(mIsSecondModeEnabled ?
R.layout.layout_second_mode_item :
R.layout.layout_first_mode_item, parent, false);
return new MyHolder(view);
}
public void setModeEnabled(boolean enabled) {
mIsSecondModeEnabled = enabled;
notifyDataSetChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
该代码无法完全正确地工作。当我打电话给setModeEnabled(true)一些显示layout_first_mode_item布局的项目时。
如何实现呢?
java android android-layout android-view android-recyclerview
我有MainActivity很多Fragments 并且在一个特定的片段中我想在系统栏后面绘制,所以我在运行时应用以下标志:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
Run Code Online (Sandbox Code Playgroud)
我现在想要的是当用户退出Fragment并输入另一个以删除该标志时,状态栏后面没有内容。我尝试将 null 作为参数传递给setFlags()方法,但这给出了错误。我已经搜索remove()或unSet()方法,但不存在。那么我应该如何删除另一个标志Fragment?
我正在尝试使用AndroidJunit4测试RecyclerView,这是我的测试代码:
package com.kaushik.myredmart.ui;
// all includes
@RunWith(AndroidJUnit4.class)
public class ProductListActivityTest {
@Rule
public ActivityTestRule<ProductListActivity> rule = new ActivityTestRule<>(ProductListActivity.class);
@Test
public void ensureListViewIsPresent() throws Exception {
ProductListActivity activity = rule.getActivity();
View viewByIdw = activity.findViewById(R.id.productListView);
assertThat(viewByIdw,notNullValue());
assertThat(viewByIdw, instanceOf(RecyclerView.class));
RecyclerView productRecyclerView = (RecyclerView) viewByIdw;
RecyclerView.Adapter adapter = productRecyclerView.getAdapter();
assertThat(adapter, instanceOf(ProductAdapter.class));
}
}
Run Code Online (Sandbox Code Playgroud)
我正面临检查适配器的问题.虽然productRecyclerView传递非null测试和RecyclerView的实例,但它在最后一行中跟随错误:
java.lang.AssertionError:
Expected: an instance of com.kaushik.myredmart.adapter.ProductAdapter
but: null
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
at com.kaushik.myredmart.ui.ProductListActivityTest.ensureListViewIsPresent(ProductListActivityTest.java:45)
Run Code Online (Sandbox Code Playgroud)
代码中有什么问题?
java android recycler-adapter android-recyclerview android-junit
这个问题已在这里提出,但它没有解决方案.
我有一个WebView.我想将最小高度设置为WebViewusing minHeight属性,但它不起作用.相同的属性适用于Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anshul.webview.WebActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="400dp"></WebView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="150dp"
android:text="This is a Button. It's minHeight is set to 150 dp and it works !!"/>
Run Code Online (Sandbox Code Playgroud)
显然,从下图中,WebView不支持该minHeight属性.有谁知道这个问题的解决方案?
我有一个动画师infinite_rotation,定义为:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="rotation"
android:repeatCount="infinite"
android:valueFrom="0"
android:valueTo="360"
android:duration="2000" />
</set>
Run Code Online (Sandbox Code Playgroud)
当时间(时间不确定)到来时我不再需要这个,我打电话infinite_animator.cancel().然后在其布局容器上播放fade_out动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="alpha"
android:repeatCount="0"
android:valueTo="0.0"
android:duration="1000" />
</set>
Run Code Online (Sandbox Code Playgroud)
生成的动画是,旋转按预期停止,但在淡出时停顿.我错过了什么?
以下是它的外观:
更新:我在使用Kitkat OS的旧三星Tab 4上测试了上述问题.我刚刚使用Marshmallow OS测试了一款相当新的三星Tab 4.动画效果很好.所以我想更好的问题是如何修复旧设备/操作系统上的草率动画?
这是动画调用:
private void animateRefreshButton() {
ImageView iv_refresh = (ImageView) findViewById(R.id.iv_refresh);
if(infinite_animator == null) {
infinite_animator = AnimatorInflater.loadAnimator(this, R.animator.refresh_rotate);
}
infinite_animator.setTarget(iv_refresh);
infinite_animator.start();
}
Run Code Online (Sandbox Code Playgroud)
hideRefreshButton()应用程序确定刷新完成时启动.这是取消和淡出动画的调用:
private void hideRefreshButton() {
if(infinite_animator != null) {
infinite_animator.cancel();
}
Animator anim = AnimatorInflater.loadAnimator(this, R.animator.refresh_fadeout);
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator …Run Code Online (Sandbox Code Playgroud) android ×10
java ×7
android-view ×1
animation ×1
c# ×1
datepicker ×1
flags ×1
java-threads ×1
jvm ×1
process ×1
scope ×1
service ×1
webview ×1